The following two C# scripts allow the player to hit a triggering collider on a checkpoint object and save its location in a public currentCheckpoint variable that will later be used by a respawn/teleport script. The first script derives from the ‘Triggerable’ script provided by my Level Design professor, Mr. Lenny Eusebi.
using UnityEngine;
using System.Collections;
public class CheckPoint : Triggerable {
public GameObject checkpoint;
// Use this for initialization
void Start () {
checkpoint = gameObject;
}
// Update is called once per frame
void Update () {
}
public override void OnTrigger(Collider triggeringCollider){
}
public void OnTriggerEnter (Collider triggeringCollider){
CheckPointManager checkPointManager = triggeringCollider.GetComponent
checkPointManager.currentCheckpoint = checkpoint;
}
}
// Next Script!
using UnityEngine;
using System.Collections;
public class CheckPointManager : MonoBehaviour {
public GameObject currentCheckpoint;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}