Hello smart people!
I am trying to attain the legendary skill of mastering how to make my scripts talk with any GameObject and their components wherever they are. To do that, i watched a couple of tutorials like Live Training 10th July 2014 - Communicating between Components & GameObjects - YouTube, but my brain still seem to resist to smartness :(.
So far, i have understood than in order to do that, i first need my script to find the right gameobject in my scene (if the script is not attached directly to it), and assign it to a variable, with for example:
myVariable = GameObject.Find ("MyGameObjectName");
Then, when i have found this gameobject (and eventually summoned it if it was not in my scene), i find myself at loss to figure out how to call the right component (and inherently, how to call the right sub-element.
For example, i have at the moment a game object for my UI with :
RectTransform, CanvasRenderer,UI Controller (Script),Grid Layout Group (Script)
In order to modify the RectTransform 's Pivot X for example, my logic tells me to add to my script:
myVariable.GetComponent<RectTransform> ();
myVariable.RectTransform.Pivot.x = 0.75;
…Which get all red and bad, and i don’t understand why.
I am also not knowing how i am supposed to call the component GridLayoutGroup. I suppose there is a even dirtier trick in the sense that it is written (script)…
To give you another example that i find confusing, if i would type myVariable.transform.position.x
, is it changing the RectTransform
, or another hidden transform that i don’t know of ? It is confusing because i would think that logically, this should be called instead myVariable.RectTransform.position.x
or something.
So the point of all that is:
What’s the big idea ? What is the core concept that i am missing ?
I am so confused !