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

     }
 }
相关推荐
五仁烧饼10 小时前
Unity Addressables 静默资源策略
游戏·unity·addressables
ue星空17 小时前
【Godot】更换编辑器外观主题
编辑器·游戏引擎·godot
fanfan_hongyun18 小时前
unity 与cad 坐标系映射
unity·游戏引擎
神码编程20 小时前
【Unity】 HTFramework框架(七十)MultiChoiceDropdown可多选的下拉菜单
unity·游戏引擎·ugui·dropdown·下拉菜单
ue星空1 天前
Godot 2D像素游戏移动抖动、模糊问题解决方案
游戏·游戏引擎·godot
淡海水1 天前
15-07-YooAsset面试篇-Unity性能优化与内存管理
java·unity·面试·性能优化·c#·游戏引擎
ue星空1 天前
【Godot】AudioStreamPlayer2D音频播放
游戏引擎·音视频·godot
zhchyun20082 天前
# 【Unity UI 进阶】仿 Element UI 打造企业级 Unity UI 组件库(03)
unity
淡海水2 天前
15-02-YooAsset面试篇-Unity架构设计与源码
java·unity·面试·c#·游戏引擎·yooasset
郝学胜-神的一滴3 天前
中级OpenGL教程 030:gl_FragCoord解锁区域渲染与深度可视化新姿势
c++·unity·游戏引擎·图形渲染·unreal engine·opengl