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 () {

}
}

About the author

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>