kingBook

导航

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));   
    }
}

 

posted on 2016-04-12 23:30  kingBook  阅读(604)  评论(0编辑  收藏  举报