【发布时间】:2019-12-03 02:35:54
【问题描述】:
我有一个脚本应该在 2 个位置之间移动平台。 平台移动到 pos1,但随后停止....
这是我的代码: 使用 System.Collections; 使用 System.Collections.Generic; 使用 UnityEngine;
public class Platform : MonoBehaviour
{
public Transform pos1, pos2;
public float speed;
public Transform startPos;
Vector3 nextPos;
// Start is called before the first frame update
void Start()
{
nextPos = pos1.position;
}
// Update is called once per frame
void Update()
{
if (transform.position == pos1.position)
{
nextPos = pos2.position;
}
if (transform.position == pos2.position)
{
nextPos = pos1.position;
}
transform.position = Vector3.MoveTowards(transform.position, nextPos, speed * Time.deltaTime);
}
private void OnDrawGizmos()
{
Gizmos.DrawLine(pos1.position, pos2.position);
}
}
【问题讨论】: