那麼,你只執行Vector3.MoveTowards
只有一次,所以你的ghost
只移動一步。你需要的是在Update
與任何標誌的幫助,在Coroutine
下一些condition.Like執行此,
using UnityEngine;
using System.Collections;
public class MaidTriggeris : MonoBehaviour {
public GameObject light;
public GameObject sing;
public GameObject ghost;
public float speed;
public GameObject target;
// Use this for initialization
void Start() {
light.SetActive(true);
}
// Update is called once per frame
void OnTriggerEnter(){
light.SetActive (false);
DestroyObject (sing);
StartCoroutine("MoveGhost");
}
IEnumerator MoveGhost(){
while(Vector3.Distance(ghost.transform.position, target.transform.position) > 1.0f) // Change this value accordingly
{
float step = speed * Time.deltaTime;
ghost.transform.position = Vector3.MoveTowards(ghost.transform.position, target.transform.position, step);
yield return new WaitForEndOfFrame();
}
}
}
上面的代碼片段並不雖然測試。所以如果需要做一些調整。
你確定幽靈和目標有不同的位置,他們不是父母的孩子嗎? –
@Hanza Hasan我相信。 – NeuTronas