Hello everyone.
I have two monsters gameobject, each of them has an empty gameobject children with a collider and a script on it. The first monster does the OntriggerEnter2D of that script perfectly. The second monster doesn’t.
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.layer == enemylayer && this.gameObject.layer == playerlayer)
{
other.GetComponent<EnemyController>().DamageRecieved(damage);
player_mana.GetComponent<Slider>().value = player_mana.GetComponent<Slider>().value - 1.0f;
}
if (other.gameObject.layer == playerlayer && this.gameObject.layer == enemylayer)
{
other.GetComponent<PlayerController>().DamageRecieved(damage);
}
Line 10 is what gives the error on the second monster. Error is NullReferenceException: Object reference not set to an instance of an object
I don’t get it at all…