I am trying to get my enemy to take damage, however it is not working. I know the reason: the box colliders on not triggering the OnTriggerEnter
message. I do not know why. Here is my code:
using UnityEngine;
public class EnemyBaseScript : MonoBehaviour
{
public float health;
private Weapon weaponGettingHitBy;
private void OnTriggerEnter(Collider col)
{
Debug.Log("OnTriggerEnter was called");
if (col.gameObject.CompareTag("Weapon"))
{
weaponGettingHitBy = new Weapon(
col.gameObject,
col.gameObject.GetComponent<WeaponBaseScript>().damageDealing
);
health -= weaponGettingHitBy.damageDealt;
Debug.Log("Took damage from weapon.");
}
}
}
The code for weapons
using UnityEngine;
public class WeaponBaseScript : MonoBehaviour
{
public float damageDealing;
}
Images of the box colliders:
(I know that some of the box colliders are off it is because I was testing around, assume all are enabled)