加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

Unity中Line Renderer画线的使用

(2014-07-24 15:23:29)
分类: unity3d

  LineRenderer线渲染器主要是用于在3D中渲染线段,虽然我们也可以使用GL图像库来渲染线段,但是使用LineRenderer我们可以对线段进行更多的操作,例如:设置颜色,宽度等。在这里要注意LineRenderer渲染出的线段的两个端点是3D世界中的点,即他是属于世界坐标(World Point)中的。

       LineRenderer是以组件形成存在的,首先我们新建一个空的Game Object,然后我们选择“Component→Effects→Line Renderer”,即可为其添加LineRenderer组件了。

http://img.blog.csdn.net/20130531095355409Renderer画线的使用" />

 

其实我们也可以通过脚本来为其添加LineRenderer组件:

[csharp] view plaincopy
  1. LineRenderer lineRenderer gameObject.AddComponent();  


 

获取LineRenderer组件:

[csharp] view plaincopy
  1. lineRenderer GetComponent();  



public class MyControls : MonoBehaviour {
 public Color c1=Color.yellow;
 public Color c2=Color.red;
 private int LengthOflineRenderer=0;
 private int index=0;
 LineRenderer lineRend;
 Vector3 position;
 // Use this for initialization
 void Start () {
  lineRend = gameObject.AddComponent ();
  lineRend.SetColors (c1,c2);
  lineRend.SetWidth (0.1f,0.1f);
  lineRend.SetVertexCount (LengthOflineRenderer);
 }
 
 // Update is called once per frame
 void Update () {
  lineRend = GetComponent ();
  if (Input.GetMouseButtonDown (0)) {
   print("1");
   position=new Vector3(Input.mousePosition.x,Input.mousePosition.y,1.0f);
   LengthOflineRenderer++;
   lineRend.SetVertexCount(LengthOflineRenderer);
  }
  while (index
   print("2");
   lineRend.SetPosition(index,position);
   index++;
  }
 }
 void OnGUI()
 {
  GUILayout.Label ("鼠标的x轴"+Input.mousePosition.x);
  GUILayout.Label ("鼠标的y轴"+Input.mousePosition.y);
 }
}

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有