Messaging another gameObject

Hi there,

I’m new here. I don’t know how to send (“Fallen”) message from, a cube (that has fallen from one platform) to a Script in the main camera that shoud add 100 points for every cube that falls.

It’s pretty basic, i guess.

Thank you for reading.

You should probably explain exactly what you’re trying to do. I don’t script in Unity, but checked out the scripting section, and this was the first one I read…I don’t quite get what you’re trying to do. Even though I don’t script, I should be able to understand what you mean…

You have plat forms and cubes fall off them how, and why?

what kind of game are you making?

if it was a little more informative people could probably point you in the right direction faster :slight_smile:

The game basicly consist of shooting cubes to a wall made of similar cubes that remains in a platform. I want the game to add 100 points for every cube (not the shot ones) that falls from the platform. So the objective would be shoot the cubes off the platform.

I’m trying to make the falling cubes, when they reach -10 in the position.y, to send the (“Fallen”) message to a script in another gameObject.

I hope it’s easier to understand now. Thanks

the usually way to send messages is to use the SendMessageUpwards command. each cube will need a reference to the fallen game object:

cube.js

var otherGameObject : GameObject;  // you would need to drag the game object 
                                                      //onto this var

function Update(){
     
     if (transform.position.y <= -10){
         otherGameObject.SendMessageUpwards("Fallen", SendMessageOptions.DontRequireReceiver);
     }

}

There’s a few other ways to do this, but this is usually the quickest and easiest. You can also send a single parameter using SendMessageUpwards, but if you need to send more than that, you’ll have to get a reference to the actual script and call it directly, rather than sending a message to its game object.

It worked. Thanks, very much. That realy helped!