I have 2 objects in a 2D game. One moves forward in a straight line while the other moves in the Y-axis based on where the mouse is. The one that moves in a straight line has a 2D Collider and the the box has a 2D Rigidbody. The code I have attached to the box is:
using UnityEngine;
using System.Collections;
public class KillPlayer : MonoBehaviour {
// Update is called once per frame
void Update () {
}
void OnTriggerEnter2D(Collider2D other) {
Debug.Log(other.gameObject.tag);
if (other.name == "Player") {
Destroy (gameObject);
}
}
}
I get nothing in the console as I run the program. I tried to put the program on the box, and give a tag to the player, still doesn’t work.