using UnityEngine;
using System.Collections;
public class MyLine : MonoBehaviour
{
private LineRenderer _line;
private Vector3 _mouse3Dpos;
private int _index= 0;
private int _lengthOfLineRenderer = 0;
void Start()
{
_line = GetComponent<LineRenderer> ();
_line.material = new Material(Shader.Find("Particles/Additive"));
_line.SetColors (Color.red, Color.black);
_line.SetWidth (0.02f, 0.02f);
}
void Update()
{
// if (Input.GetMouseButton(0)) {
_mouse3Dpos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition.y,1.0f));
//
//
// }
transform.Translate (new Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical")));
if (Input.GetAxis("Horizontal")!=0 || Input.GetAxis("Vertical")!=0 ) {
LineSetVerterCount ();
_mouse3Dpos = transform.position;
}
while (_index < _lengthOfLineRenderer) {
_line.SetPosition (_index, _mouse3Dpos);
_index++;
}
if (Input.GetKeyDown(KeyCode.Q)) {
_lengthOfLineRenderer = 0;
_index = 0;
_line.SetVertexCount (0);
}
}
void LineSetVerterCount()
{
_lengthOfLineRenderer++;
_line.SetVertexCount (_lengthOfLineRenderer);
}
}
【Unity】LineRenderer
最新推荐文章于 2024-03-30 16:27:12 发布