时间:2021-05-20
我就废话不多说了,大家还是直接看代码吧~
private LineRenderer line;//画线line = this.gameObject.AddComponent<LineRenderer>();//只有设置了材质 setColor才有作用line.material = new Material(Shader.Find("Particles/Additive"));line.SetVertexCount(2);//设置两点line.SetColors(Color.yellow, Color.red); //设置直线颜色line.SetWidth(0.01f, 0.01f);//设置直线宽度//设置指示线的起点和终点line.SetPosition(0, initPosition);line.SetPosition(1, newPosition);下面是以物体position为圆心,半径为R,在xz平面上的画圆
public float R;//半径 public int N;//不要超过45 line.SetVertexCount(N+1);//这里要加1,达成闭合曲线 for (int i = 0; i < N + 1; i++){ float x = R * Mathf.Cos((360 / N * i) * Mathf.Deg2Rad) + transform.position.x; //确定x坐标 float z = R * Mathf.Sin((360 / N * i) * Mathf.Deg2Rad) + transform.position.z; //确定z坐标 line.SetPosition(i, new Vector3(x, transform.position.y, z)); }补充:Unity 通过LineRenderer组件画线段
using System.Collections;using System.Collections.Generic;using UnityEngine; public class DrawLineByMouse : MonoBehaviour { //画线组件预制体 public Transform gestureOnScreenPrefab; private int strokeId = -1; private Vector3 virtualKeyPosition = Vector2.zero; private Rect drawArea; private RuntimePlatform platform; private int vertexCount = 0; private List<LineRenderer> gestureLinesRenderer = new List<LineRenderer>(); private LineRenderer currentGestureLineRenderer; //GUI private string message="what is this ?"; private bool recognized; private string newGestureName = ""; void Start() { platform = Application.platform; drawArea = new Rect(0, 0, Screen.width - Screen.width / 3, Screen.height); } void Update() { if (platform == RuntimePlatform.Android || platform == RuntimePlatform.IPhonePlayer) { if (Input.touchCount > 0) { virtualKeyPosition = new Vector3(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y); } } else { if (Input.GetMouseButton(0)) { virtualKeyPosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y); } } if (drawArea.Contains(virtualKeyPosition)) { if (Input.GetMouseButtonDown(0)) { ++strokeId; // Transform tmpGesture = Instantiate(gestureOnScreenPrefab, transform.position, transform.rotation) as Transform; // currentGestureLineRenderer = tmpGesture.GetComponent<LineRenderer>(); GameObject go = new GameObject("LineRenderer"); go.transform.position = Camera.main.transform.position; go.transform.rotation = Camera.main.transform.rotation; currentGestureLineRenderer = go.AddComponent<LineRenderer>(); currentGestureLineRenderer.startWidth = 0.1f; gestureLinesRenderer.Add(currentGestureLineRenderer); vertexCount = 0; } if (Input.GetMouseButton(0)) { currentGestureLineRenderer.SetVertexCount(++vertexCount); currentGestureLineRenderer.SetPosition(vertexCount - 1, Camera.main.ScreenToWorldPoint(new Vector3(virtualKeyPosition.x, virtualKeyPosition.y, 10))); } } } void OnGUI() { GUI.Box(drawArea, "Draw Area"); GUI.Label(new Rect(10, Screen.height - 40, 500, 50), message); if (GUI.Button(new Rect(Screen.width - 100, 10, 100, 30), "clear line")) { foreach (LineRenderer lineRenderer in gestureLinesRenderer) { lineRenderer.SetVertexCount(0); Destroy(lineRenderer.gameObject); } gestureLinesRenderer.Clear(); recognized = true; } }}以上为个人经验,希望能给大家一个参考,也希望大家多多支持。如有错误或未考虑完全的地方,望不吝赐教。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
在亿图图示中,你可以通过钢笔工具绘制直线,该直线由两个锚点组成。点击钢笔工具,移动后再点击形成两个锚点后形成直线,继续点击,你可以绘制出折线段。软件名称:Edr
本文实例为大家分享了unity实现弧形移动的具体代码,自定角度,供大家参考,具体内容如下两点之间弧形移动usingUnityEngine;usingSystem
摘要:算法导论之FloydWarshall算法求一个图中任意两点之间的最短路径FloydWarshall算法是通过动态规划来计算任意两点之间的最短路径如果普通求
霍夫直线检测参数说明:cv::HoughLinesP(InputArraysrc,//输入图像(8位灰度图像)OutputArraylines,//输出直线两点
CAXA在绘制二维图标注尺寸时,经常需要标注两点之间的距离,但图中往往不是孤立的两点,在标注时很难选到自己想要标注的部位,该怎么办呢?下面我们就来分享一个小技巧