【Unity】LineRenderer

来源:互联网 发布:淘宝考试答案50题2016 编辑:程序博客网 时间:2024/06/07 04:48
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);}}

0 0
原创粉丝点击