How to Send Message to other GameObject

how do you SendMessage to another object?

i am trying to send addAmmo from a box on collider enter with the Player,

for some reason i can only recieve the message on scripts attached to the player i want to go to my Gun.

var ammo = 20;

function OnTriggerEnter (collision : Collider) {

if (collision.gameObject.FindWithTag ("Player"))
    DestroyObject (gameObject);

i get the Debug |Log so its workin'...

function addAmmo (ammo : float) {

Ammo += ammo;


however this dosent.

Put this on the ammo box (in a collision check):


Since you're assigning an integer to your ammo variable I suspect the `addAmmo()` function should take an integer as well (instead of float):

function addAmmo (ammo : int) {
    Ammo += ammo;

Do you mean that the message is sent only to the Player object, and you need it to propagate down the object hierarchy to your gun object???

If so, you want to use BroadcastMessage instead of SendMessage (with the same parameters).