- Home /
Question by
mthicke2 · Mar 21, 2013 at 05:27 AM ·
gameobjectobjectfind
send object in sendMessage
I want to send a gameObject to another object. I'm getting some weird behaviour when I try to access the name of the object after passing it. See code below. The Debug.Log in Cube will print the name of the object. The Debug.Log in Main Camera will give an error: Assets/MainCameraScript.js(12,30): BCE0019: 'name' is not a member of 'Object'.
What gives? How do I pass an object to another script and access it's name?
//this script is on 'Cube' in CubeScript
function OnMouseDown()
{
Debug.Log(this.gameObject.name);
GameObject.Find("Main Camera").SendMessage("PrintName", this.gameObject);
}
//this script is on the 'Main Camera' in MainCameraScript
function PrintName (obj)
{
Debug.Log(obj.name);
}
Comment
Best Answer
Answer by mthicke2 · Mar 21, 2013 at 05:36 AM
solved
Needed to put: function PrintName (obj : GameObject)
Your answer
![](https://koobas.hobune.stream/wayback/20220613094815im_/https://answers.unity.com/themes/thub/images/avi.jpg)