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

     }
 }
相关推荐
tealcwu6 小时前
【Unity高级】Unity URP:构建同时支持 2D 与 3D 场景的项目完全指南
3d·unity·游戏引擎
淡海水11 小时前
10-01-互操作-C#与C++边界的内存管理
unity·c#·游戏引擎·.netcore·gc
小小数媒成员13 小时前
UGUI原理(一)
开发语言·游戏·unity·游戏引擎
暴走约伯14 小时前
【VFX工具链源码拆解 04】拯救丢失的绑定:Timeline 一键克隆与层级相对路径重映射算法
unity·c#·游戏引擎·硬件工程
小小数媒成员16 小时前
Unity UGUI布局组件(LayoutGroup、ContentSizeFitter、LayoutElement)详解
unity·游戏引擎
tealcwu16 小时前
【Unity基础】Unity输入与Time.deltaTime的使用原则
unity·游戏引擎
chen_2271 天前
godot做仪表hmi
游戏引擎·godot
郝学胜-神的一滴1 天前
AI 编程智能体 22:解析器赋能与实战落地全指南
人工智能·程序人生·游戏·unity·游戏引擎
BuHuaX2 天前
Lua 与 ToLua:运行机制及热更新原理
开发语言·unity·junit·c#·lua
Solange__2 天前
在线3D预览器、Blender和游戏引擎怎么选?按5类任务比较格式、隐私与编辑性
人工智能·游戏·3d·游戏引擎·blender·1024程序员节·关卡设计