Ok so i have a player, a weapon(sword) and an enemy. The sword is attached as a child to the hand bone of the player and has a box collider. I want to detect collisions with the enemy so i can kill it.
using UnityEngine;
using System.Collections;
public class WeaponCollision : MonoBehaviour {
void Update () {
}
void OnCollisionEnter(Collision col) {
Debug.Log ("Collision");
if (col.gameObject.tag == "Enemy") {
Destroy(col.gameObject);
}
}
}
this script is attached to the weapon object, but its not working, the “Collision” is not being logged either.
Does the enemy object have a collider attached to it too?
– darthtelleYes it has a Capsule Collider attached
– Heffalusdoes it pick up the collision?
– El_MaxoI dont know, how would i check that? run the same script on the enemy object and use Debugger to log?
– HeffalusOne of the colliders needs to be tagged "IsTrigger", is that checked on one of the colliders?
– Ramsdal