unity LineRenderer
using UnityEngine; using System.Collections; public class Spider:MonoBehaviour { private LineRenderer _lineRenderer; void Start() { _body=GetComponent<Rigidbody2D>(); _lineRenderer=gameObject.AddComponent<LineRenderer>(); _lineRenderer.SetVertexCount(2); Material material=new Material(Shader.Find("Sprites/Default")); material.color=Color.white; _lineRenderer.material=material;//要设置材质否则看不到颜色变化,永远是紫色 _lineRenderer.SetColors(Color.white,Color.white); _lineRenderer.SetWidth(0.01f,0.01f);//设置为1个像素时,需要设置主相机适合设计分辨率 _lineRenderer.SetPosition(0,new Vector3(0,0,0)); _lineRenderer.SetPosition(1,new Vector3(100,0,0)); } }