book
1
Why am I getting a null reference exception when I call the hear noise function?
NullReferenceException: Object reference not set to an instance of an object
this class is attached to a crate object and when it falls it calls the enemy object to come to it.
public class Crate : MonoBehaviour {
public AudioClip collisionNoise;
EnemyCylinder EC;
//turns on alien hear sound.
void OnCollisionEnter(Collision other)
{
AudioSource.PlayClipAtPoint(collisionNoise, transform.position);
//BroadcastMessage("HearNoise", this.transform.position);
EC = GetComponent<EnemyCylinder>();
EC.HearNoise(this.transform.position);
}
}
Jamora
2
There is no EnemyCylinder script on the GameObject. You need to have a reference to an object that has the EnemyCylinder script. I would assume it is on the colliding gameobject.