I've created a GUI interface in my game and I have interactive buttons that I've managed to get working. The first thing I did was get objects in the world to change color when I push a button.
Now what I'd like to do is have another objects variable change based on pushing the button.
Now the code for changing the variable is in VARIABLE.CS
The thing is that the object that has the variable that needs to be changed isn't a parent, it is a child of a gameobject. Though I'm not sure if that matters considering "var object" in my JS is the correct gameobject.
I'm not sure if I need to use a Broadcast or Send message. Or if it's simply dot operators or what not.
Okay lets try this again...
All the scripts attached to the objects will be in the same folder to get rid of that variable. These two objects are not related to each other at all (parent child wise)
Object one = GUIEditor. I'm dealing with one piece of it, GUI_Button. script below, GUI_Button.JS:
Okay so that's the script with the button. This next script is the script that has the variable that needs to be changed.
Object two = GUITEST. It is just a cube I"m going to change its color just to make this concept work. The script attached is TESTVARIABLE.CS:
Dominic, feel free to respond to this edit in a new answer so it's easier to follow comments for people in the future. Thanks for the help man, really appreciate it.
I am copy pasting the answer directly from: http://answers.unity3d.com/questions/145836/broadcastmessage-functionality-help.html
This answer was given by: Alec Slayden
If your game is such that you cannot alter the hierarchy of the objects in question, you can refer directly
for example, instead of BroadcastMessage, you could use:
Where 'OtherScript' is the name of the actual changevar script, minus the extension. If you expect to use
To change variables in different scripts one has to make said variables Static for example
In your VARIABLE.CS script
At this point you can change your variable in your BUTTON.JS script by calling it through the other script with the convention of
so you would say
in your BUTTON.JS script to change it
Hope that helped :)