Want to apply SendMessage, but stuck!

Hi everyone,

As per Unity’s doc, for using SendMessage, I’m using the following scripts on two gameobjects.

//GameObjects
CubeMaster
CubeSlave

I’ve the following scripts bound on the above objects…

// on CubeMaster → scrMaster.js
// on CubeSlave —> scrSlave.js

The following code is contained in the scripts…

// scrMaster.js

function OnGUI()
{
if(GUILayout.Button(“sendMessage”))
{
gameObject.SendMessage(“makeRotation”,30.0,SendMessageOptions.DontRequireReceiver);
}
}


// scrSlave.js

function makeRotation ( val : float )
{
gameObject.transform.Rotate(Vector3.up, val );
}


Now, my problem is, my CubeSlave should rotate by 30 degrees, but its not!

Check this page for documentation of SendMessage,

and help me where am I going wrong!

GameObject.Find(“CubeSlave”).SendMessage(“makeRotation”, …

EDIT: to clarify “gameObject” will point to the current GameObject that the executing script is attached to. In this case, when you have scrMaster.js on CubeMaster saying: gameObject.SendMessage(…), you’re really saying: this.SendMessage(…). So instead, you have to target your CubeSlave, hence GameObject.Find(“CubeSlave”)