- Home /
Access variable in another object
The object I'm trying to access is called "global", the script attached to it is called "globals". Please show me in code how to do this, I've tried copy+pasting many other answers I've seen on other questions and there's always an error. Yes I've obviously changed the names when I pasted other code, they don't work.
Answer by robertbu · Nov 30, 2013 at 05:09 AM
In Javascript/Unityscript:
var gbls : globals = GameObject.Find("global").GetComponent(globals);
In C#:
globals gbls = GameObject.Find("global").GetComponent<globals>();
thank you that did the trick, I knew it involved GetComponent somehow. The lesson here for me today is CaPiTaLs can make all the difference! I.$$anonymous$$, GameObject ins$$anonymous$$d of gameObject, and so on.
Your answer
Follow this Question
Related Questions
Create a persistent GameObject using Singleton 3 Answers
Global Scripts/Variables 1 Answer
Global variables questions 5 Answers
How to make a global settings Editor Window for my game 0 Answers
Global update function for network 1 Answer