资 源 简 介
unity 实现鼠标、移动端手势画线
public class DrawLineByMouse : MonoBehaviour {
public Material mat;
public List vertexPosList= new List();
public List breakFlagList = new List(); //当为真时,需要断开
public Color lineColor;
Vector2 _lastMousePos;
Vector2 _curMousePos;
bool _canDrawLine=false;
bool _mouseButtonHaveUp = false;
void OnGUI(){
if (!Input.GetMouseButton(0))
{
if (vertexPosList.Count > 1)
{
_mouseButtonHaveUp = true;
}
return;
}
_curMousePos = new Vector2(Input.mousePosition.x / (float)Screen.width, Input.mousePosition.y / (float)Screen.height);
if (Vector3.Distance(_lastMousePos,_curMousePos)>0.001f)
{
vertexPosList.Add(_curMousePos);