It isn't hitting?

I did the code for this lecture but the projectiles won’t hit.

Here’s the code for my EnemyBehavior:

using UnityEngine;
using System.Collections;

public class EnemyBehavior : MonoBehaviour {
	public float health = 150;

	void onTriggerEnter2D(Collider2D collider){
		Projectile missile = collider.gameObject.GetComponent<Projectile>();
		if (missile) {
			health -= missile.GetDamage();
			missile.Hit();
			if (health <= 0) {
				Destroy(gameObject);
			}
		}
	}
}

And the code for my Projectile:

using UnityEngine;
using System.Collections;

public class Projectile : MonoBehaviour {
	public float damage = 100f;

	public void Hit(){
		Destroy(gameObject);
	}

	public float GetDamage(){
		return damage;
	}
}

Pls help! Thanks!

Hi,

C# is case-sensitive, the correct method name is OnTriggerEnter2D, note the capital “O”.

Hope this helps. :slight_smile:


See also;

Thanks! I made the o a capital O and now it’s working great!

1 Like

You’re very welcome, glad you can move forward again :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms