Broadcastmessage not working, I think.

Have a question, I am trying to use a collision function(c# code)for some projectiles and then the object being shot, the on collision code in the projectile is this:

void OnCollisionEnter(Collision collision)
	{
     if (collision.contacts[0].thisCollider.tag == "Enemy")
            Debug.Log("We have collided");
            BroadcastMessage("ApplyDamage",Mathf.Infinity, SendMessageOptions.DontRequireReceiver);
            Destroy(gameObject);

}

Nothing works with this, but if I comment out the if statement I only get the console log message the Broadcastmessage still don’t work. I have colliders on each object and the collider on the object that I am shooting is called enemy but still nothing. Is there anything wrong with what I am doing and any help is appreciated.

You have to specify the object to BroadcastMessage to. Right now it’s just being called on the object that has that OnCollisionEnter function.

–Eric

How would I manage that, from what I understood is that when you applydamage it is suppose to call all the scripts with applydamage?

Thanks for that tip Eric, I did something different my code now reads

void OnCollisionEnter(Collision collision)
	{
       if (collision.contacts[0].thisCollider.tag == "Enemy")
            Debug.Log("We have collided");
            BroadcastMessage("ApplyDamage",SendMessageOptions.RequireReceiver);
            Destroy(gameObject);

	}

Now I get the error
BroadcastMessage ApplyDamage has no receiver!
UnityEngine.Component:BroadcastMessage(String, Object, SendMessageOptions)
Anything that I am doing wrong here?

BroadcastMessage is just sending to the object the script is attached to. You need to specify the object to send to; “someObject.BroadcastMessage”, where “someObject” is derived from the collision info.

–Eric