unity 通过LineRenderer 动态划线

private LineRenderer line1;
        
//画线
line1 = this.gameObject.AddComponent<LineRenderer>();
//只有设置了材质 setColor才有作用
line1.material = new Material(Shader.Find("Particles/Additive"));
line1.SetVertexCount(2);//设置两点
line1.SetColors(Color.yellow, Color.red); //设置直线颜色
line1.SetWidth(5f, 10f);//设置直线宽度
      
//设置指示线的起点和终点
line1.SetPosition(0, A.transform.position);
line1.SetPosition(1, B.transform.position);



Destroy(this.gameObject.GetComponent<LineRenderer>());

 
       

猜你喜欢

转载自blog.csdn.net/weixin_43705303/article/details/93197334
今日推荐