Unity基础(十五)LineRender画线功能

1 LineRender 画线功能组件

Loop是否起点终点自动相

绘制攻击范围 武器红外线 辅助功能 其他画线功能

cs 复制代码
void Start()
{
DrawLineRender(new Vector3(0, 0, 0), 5, 359);
line2=this.gameObject.AddComponent<LineRenderer>();
line2.loop = false;
line2.startWidth = 0.5f;
line2.endWidth = 0.5f;
line2.positionCount= 0;
}

void Update()
{
    if (Input.GetMouseButton(0))
    {
        line2.positionCount += 1;
        //如何得到鼠标转世界坐标的  对应点
        //
        nowPos = Input.mousePosition;
        nowPos.z = 10;
        
        line2.SetPosition(line2.positionCount - 1,Camera.main.ScreenToWorldPoint(nowPos));
    }
}

Corner Vertices 是角顶点 圆点 此属性指示在一条线中绘制角时使用了多少额外的顶点 增加此值,使线角看起来更圆

End Cap Vertices 终点圆角

2 画个圆功能

cs 复制代码
 public void DrawLineRender(Vector3 centerPos, float r, int pointNum)
 {
     //生成空物体 
     GameObject obj = new GameObject();
     obj.name = "R";
     LineRenderer line = obj.AddComponent<LineRenderer>();
     line.loop = false;
     line.positionCount = pointNum;
     float angle = 360f / pointNum;

     for (int i = 0; i < pointNum; i++)
     {
         line.SetPosition(i, centerPos + Quaternion.AngleAxis(angle*i, Vector3.up) * Vector3.forward * r);

     }
 }
相关推荐
旧物有情16 小时前
游戏开发常用架构 #MVP,MVC
游戏·unity·架构·mvc
勇踏前人未索之境18 小时前
Unity打包运行于鸿蒙手机
unity·智能手机·harmonyos
玖玥拾19 小时前
Unity 3D 笔记(十一)UI 框架进阶:栈弹窗交互、BasePanel 基类虚方法、DoTween 界面动画
笔记·3d·unity
郝学胜-神的一滴21 小时前
中级OpenGL教程 023:Assimp模型加载全解——从源码到架构的骈文探秘
c++·unity·游戏引擎·cmake·unreal engine·opengl
xcLeigh2 天前
Unity基础:GameObject与Component——Unity核心架构思想彻底理解
unity·教程·component·gameobject
郝学胜-神的一滴2 天前
中级OpenGL教程 022:探秘三维世界的血脉传承——物体父子关系与矩阵递归奥义
c++·线性代数·unity·矩阵·游戏引擎·unreal engine·opengl
weixin_424294673 天前
Unity的测试Edit Mode和Play Mode,有什么区别?
unity
Python私教3 天前
我用 AI 做出了第一个 Godot 贪吃蛇
人工智能·游戏引擎·godot
玖玥拾3 天前
Unity 3D 笔记(八)ScrollRect 滚动视图、NavMesh 自动寻路系统
笔记·3d·unity