赞
踩
在Unity3D根据物体运动画出实体轨迹线

在Inspector里面添加组件LineRender,线条圆滑设置如下,
颜色可以新建材质直接拖上该物体上就行。

添加脚本LineMark
using System.Collections; using System.Collections.Generic; using UnityEngine; public class LineMark : MonoBehaviour { private GameObject clone; private LineRenderer line; private int i; public GameObject obs; public GameObject run; Vector3 RunStart; Vector3 RunNext; // Use this for initialization void Start() { RunStart = run.transform.position; clone = (GameObject)Instantiate(obs, run.transform.position, run.transform.rotation);//克隆一个带有LineRender的物体 line = clone.GetComponent<LineRenderer>();//获得该物体上的LineRender组件 // //line.SetColors(Color.blue, Color.red);//设置颜色 // //line.SetWidth(0.2f, 0.1f);//设置宽度 i = 0; } // Update is called once per frame void Update() { RunNext = run.transform.position; if (RunStart != RunNext) { i++; line.SetVertexCount(i);//设置顶点数 line.SetPosition(i - 1, run.transform.position); } RunStart = RunNext; // if (Input.GetMouseButtonDown(0)) // { // clone = (GameObject)Instantiate(obs, obs.transform.position, transform.rotation);//克隆一个带有LineRender的物体 // line = clone.GetComponent<LineRenderer>();//获得该物体上的LineRender组件 // line.SetColors(Color.blue, Color.red);//设置颜色 // line.SetWidth(0.2f, 0.1f);//设置宽度 // i = 0; // print ("GetMouseButtonDown"); // } // if (Input.GetMouseButton(0)) // { // i++; // line.SetVertexCount(i);//设置顶点数 // line.SetPosition(i - 1, Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 15)));//设置顶点位置 // print ("GetMouseButton"); // // } } }
将上面的Line放在OBS里面,对应需要画出的物体直接拖入右侧的
—
小技巧:想画出对应阶段的轨迹曲线可以通过启用和不启用脚本实现,或者改换透明材质。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。