Getting information from a different object.

I would like to get some developer set information from a GameObject I have a reference for. For example to get the tag or instanceId is simple if object is in variarable otherObject
(note the code below is JavaScript but I program in Boo so there may be lots syntax errors but the logic should be right)

xTag = otherObject.tag;
xID = otherObject.instanceID();

I have many attribute so I don’t want to use Tag.

curently I am doing a callback with SendMessage but this pretty messy. in first object script

otherObject.SendMessage("informMe",transform);

in otherObject script

function  informMe(sender){
		sender.SendMessage("SetOrigin",origin);
}

back in first object

function SetOrigin(value){
    origin = value;
}

all this to get origin from otherObject.it is not very clear code and tough to follow since the execution thread goes back and forth between files alot.

I was hoping to get a return vale from the other objectScript

    xOrigin= otherobject. ... .getOrigin();

in other object

function GetOrigin(){
    return origin;
}

“…” could be various functions some how getting the a script from otherObject and then the function getorigin and executing it and getting the retun value back.

Cheers,
Grant

A script is a component of a GameObject, so get a reference to the script and call it directly…

otherScript = otherObject.GetComponent("scriptName");
xOrigin = otherScript.getOrigin();

not bad, eh?

syntax may need help, but here’s the explanation:
http://unity3d.com/Documentation/ScriptReference/index.Accessing_Other_Components.html

:sweat_smile: Thank You, How to do it was exactly where it should be in the documentation For some reason I keep reading that and thinking it returned void.

Cheers,
Grant

P.S> Great Forum, Fast, Correct , Polite answers.