I am making a 2D game and I need my player to die when it touches another object. How can I do this?!?!
using UnityEngine;
using System.Collections;
public class SandCubeistrigger : MonoBehaviour {
public static Vector3 touched_object;
public static bool Colexists=false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider other) {
if (other.gameObject.tag == "theobjecttagnameuwannatouch")
{
Colexists=true;
Destroy(this.gameObject);
}
}
void OnTriggerExit(Collider other) {
Colexists=false;
//Debug.Log("Collission does not exist");
}
void OnTriggerStay(Collider other) {
if (other.gameObject.tag == "sandcube")
{
Colexists=true;
}
}