Unity用Gizmos画线和图
概述
Camera上挂runner.cs脚本,创建几个GameObject进行点的定位,赋值给runner的ts数组runner中实现OnDrawGizmos方法,在其中用Gizmos进行绘制//runner.cs脚本using System.Collections;using System.Collections.Generic;using UnityEngine;pub...
Camera上挂runner.cs脚本,创建几个GameObject进行点的定位,赋值给runner的ts数组
runner中实现OnDrawGizmos方法,在其中用Gizmos进行绘制

//runner.cs脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class runner : MonoBehavIoUr
{
public Transform[] ts;
void OnDrawGizmos()
{
Gizmos.color = Color.green;
if (null != ts && ts.Length > 1)
{
for (int i = 0; i < ts.Length-1; i++)
{
if (null != ts[i] && null != ts[i + 1])
{
Gizmos.DrawLine(ts[i].position,ts[i + 1].position);
Gizmos.DrawIcon(ts[i].position,"icons/face");
}
}
}
}
}
@H_419_18@
注意,DrawIcon方法用到的图片,必须放在Assets/Gizmos目录中,如果有子目录,比如Assets/Gizmos/icons/,那么参数要写相对路径icon/xxx,比如上面的icon/face

浙公网安备 33010602011771号