本文共 1111 字,大约阅读时间需要 3 分钟。
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(); _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); }}
转载地址:http://gfkii.baihongyu.com/