58 lines
1.3 KiB
C#
58 lines
1.3 KiB
C#
using UnityEngine;
|
|||
|
|
using System.Collections;
|
||
|
|
|
||
|
|
public class CheckpointManager : MonoBehaviour {
|
||
|
|
public Checkpoint levelStart;
|
||
|
|
public GameObject player;
|
||
|
|
private Checkpoint lastCheckPoint;
|
||
|
|
private GameObject playerInstance;
|
||
|
|
public Camera playerCamera;
|
||
|
|
public AudioClip respawnSound;
|
||
|
|
private GameManager gameManager;
|
||
|
|
|
||
|
|
void Start () {
|
||
|
|
gameManager = GameObject.FindObjectOfType<GameManager> ();
|
||
|
|
lastCheckPoint = levelStart;
|
||
|
|
RespawnPlayer ();
|
||
|
|
}
|
||
|
|
|
||
|
|
void Update () {
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
public void OnCheckPoint(Checkpoint cp){
|
||
|
|
Debug.Log ("Enter check point: " + cp.name);
|
||
|
|
lastCheckPoint = cp;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void OnPlayerKilled(){
|
||
|
|
RespawnPlayer ();
|
||
|
|
}
|
||
|
|
|
||
|
|
void RespawnPlayer(){
|
||
|
|
if (levelStart == null) {
|
||
|
|
Debug.LogError("Level entry point is not set!");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if (player == null) {
|
||
|
|
Debug.LogError("Player respawn prototype is not set!");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (playerInstance != null) {
|
||
|
|
Destroy(playerInstance);
|
||
|
|
}
|
||
|
|
if (gameManager != null) {
|
||
|
|
gameManager.audio.volume = 2;
|
||
|
|
gameManager.audio.PlayOneShot (respawnSound);
|
||
|
|
}
|
||
|
|
|
||
|
|
playerInstance = (GameObject)Instantiate (player);
|
||
|
|
playerInstance.transform.position = lastCheckPoint.transform.position;
|
||
|
|
playerInstance.transform.rotation = lastCheckPoint.transform.rotation;
|
||
|
|
playerInstance.SetActive (true);
|
||
|
|
playerCamera.GetComponent<FollowCamera> ().target = playerInstance;
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|