我遇到了检查点系统实施的问题。所以我遵循一个教程,我得到了一个像这样的检查点系统:
带有内容的游戏对象检查点:
[SerializeField]
private Transform SpawnPoint;
void OnTriggerEnter(Collider collider)
{
if (collider.gameObject.tag == "Player")
{
SpawnPoint.position = new Vector3(transform.position.x, transform.position.y, transform.position.z);
}
}
一个游戏对象Respawn(当他重生到最后一个检查点时)
[SerializeField]
private Transform SpawnPoint;
[SerializeField]
private GameObject player;
void OnTriggerEnter(Collider collider)
{
if (collider.gameObject.tag == "Player")
{
player.transform.position = SpawnPoint.position;
}
}
但现在我想要取代游戏对象Respawn,当玩家失去生命时,只需将玩家重生为最后一个检查点。我怎样才能做到这一点 ?我试图用player.transform.position = SpawnPoint.position;
更改脚本Respawn,但它很难用......
先谢谢! PokeRwOw
答案 0 :(得分:1)
你可以在玩家gameObject中放置一个与此类似的脚本,只要你已经可以追踪他失去的生命。
//Update checks every frame, instead of only on collision with certain objects.
void Update ()
{
// Equal to or less than is to prevent errors from multiple lost lives in a short amount of time.
if(lifeVariable =< 0)
{
player.transform.position = SpawnPoint.position;
}
}