我有一个物体向玩家移动,并有一个触发器,当玩家或物体击中它时,它们会传送到地图上的另一个区域。物体朝着播放器移动而没有任何问题,直到物体通过传送器移动为止。当对象获得新的位置触发后,它便会离开屏幕。任何人都知道为什么会这样吗?
追逐玩家:
private void Update()
{
Vector3 targetPosition = new Vector3(target.transform.position.x,
target.transform.position.y,
target.transform.position.z);
transform.LookAt(targetPosition);
Monster.transform.position = Vector3.MoveTowards(Monster.transform.position,
Player.transform.position, moveSpeed);
}
传送脚本:
private void OnTriggerEnter(Collider collider)
{
if (collider.name == Player.name)
{
Player.transform.position = new Vector3(XLocation, YLocation, ZLocation);
}
if (collider.name == Monster1.name)
{
Monster1.transform.position = new Vector3(XLocation, YLocation, ZLocation);
}
}