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

     }
 }
相关推荐
郝学胜-神的一滴7 小时前
CMake 047:解锁安装阶段自定义操作,告别配置阶段提前执行坑
运维·服务器·c++·游戏引擎·图形渲染·opengl
微三云生态系统架构师-彭丹1 天前
任务卷轴积分系统架构设计:从任务状态机到合规风控的完整实现
unity·系统架构·游戏引擎
XR技术研习社1 天前
从 PICO 文档看未来短期内的 Unity 版本选择
unity·游戏引擎·xr·vr
玖玥拾1 天前
Unity 热更新(一)
unity·游戏引擎
软件黑马王子1 天前
1.non-MonoBehaviour 单例模式泛型基类
unity·前端框架·c#
KhalilRuan2 天前
Unity性能优化
unity·性能优化·游戏引擎
ellis19702 天前
u3d IMGUI[二] 编辑器扩展
unity
五仁烧饼2 天前
Unity性能优化系列内存篇 - 移动端内存优化
unity·性能优化·游戏引擎
WiChP4 天前
【V0.1B15】从零开始的2D游戏引擎开发之路
游戏引擎
zhchyun20085 天前
# 【Unity UI 进阶】仿 Element UI 打造企业级 Unity UI 组件库(06)
ui·unity·游戏引擎