Thursday, 14 March 2013

Respawn Point Script

using UnityEngine;using System.Collections;

public class RespawnManager : MonoBehaviour{

public GameObject[] RespawnPoints;

public GameObject player;


public bool enableRespawnTimer;



// Use this for initialization

void Start ()

{
//InvokeRepeating ("RespawnPlayer", 0, 5F);

}


public void RespawnPlayer ()

{
int randomIndex = Random.Range (0, RespawnPoints.Length);

player.transform.position = RespawnPoints[randomIndex].transform.position;

}



void RespawnPlayerRepeatedly ()

{
if ( enableRespawnTimer )

{
int randomIndex = Random.Range (0, RespawnPoints.Length);

player.transform.position = RespawnPoints[randomIndex].transform.position;

}

else

{

CancelInvoke();

}

}

// Update is called once per frame

void Update ()
{

if (enableRespawnTimer && !IsInvoking ("RespawnPlayer") )

{

InvokeRepeating ("RespawnPlayer", 0, 5F);
 
}

}

}

We could use this code so that if the player dies, they could respawn at the pod and start the game again. With this, you also need to add some code to the PlayerController script, which I wil be posting after this.


No comments:

Post a Comment