概述
在Unity中通过SimpleWaypointSystem在沙盘上绘制出轨迹,一个物体沿着轨迹移动。
需要实现当沙盘旋转时,物体、轨迹也跟随旋转,且物体的移动不会偏移轨迹。
重要变量:fullPosition【获取和设置补间的时间位置(包括循环,排除延迟)】
通过fullPosition的值可以动态记录物体在轨迹上的位置点,然后将记录的值重新赋值给旋转沙盘后重绘轨迹上相同的位置点。
/// <summary>
/// 记录小车在轨迹上的位置点
/// </summary>
float pathPos;
/// <summary>
/// 设置小车的位置和移动轨迹
/// </summary>
private void SetCarPosAndPath()
{
//暂停当前正在执行的动画
SandCarManager_01.GetInstance().sandCar.GetComponent<splineMove>().Pause();
//记录当前小车在轨迹上的位置点
pathPos = SandCarManager_01.GetInstance().sandCar.GetComponent<splineMove>().tween.fullPosition;
SandCarManager_01.GetInstance().sandCar.GetComponent<splineMove>().reverse = false;
StartCoroutine(RedrawPath());
}
IEnumerator RedrawPath()
{
yield return new WaitForSeconds(0.5f);//延迟调用StartMove函数+重绘路径
SandCarManager_01.GetInstance().sandCar.GetComponent<splineMove>().StartMove();
yield return new WaitForSeconds(0.05f);//延迟将小车轨迹上的位置点赋值给新轨迹对应的位置点
SandCarManager_01.GetInstance().sandCar.GetComponent<splineMove>().tween.fullPosition = pathPos;
}
最后
以上就是体贴过客为你收集整理的Unity中使用SimpleWaypointSystem控制物体移动的全部内容,希望文章能够帮你解决Unity中使用SimpleWaypointSystem控制物体移动所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复