Hello,
I have searched both these forums and Google for a solution to my issue. It seems to be fairly common for people to have issues with OnCollisionEnter(), so I hate having to repost, but I have not found any of the other solutions to be helpful.
So I have two objects, a “Footman” and a “Wall”. Both have 2D Box Colliders with triggers disabled. Both have RigidBody2D attached, with only the wall having Kinematic checked. The following code is attached to my wall gameobject;
using UnityEngine;
using System.Collections;
public class CollisionDetection : MonoBehaviour {
public int hitPoints;
// Use this for initialization
void Start ()
{
hitPoints = 100;
}
// Update is called once per frame
void Update ()
{
if(hitPoints == 0)
{
Destroy (this.gameObject);
}
}
void OnCollisionEnter(Collision col)
{
Debug.Log ("Collision!");
if(col.gameObject.tag == "Footman")
{
hitPoints =- 50;
}
}
}
I see the objects collide with each other, and the “Footman” gets stopped at the wall, but the debug statement never executes. I am either doing something really stupid, or something is broken.
Thanks a lot for any help!