how would you access the Parent's parent or the Child's child?
For example your Hierarchy is set up as:
and I wanted my Weapon to be able to access some variable from my level object's Singleton's script. How would I do that?
Also how would I access it the other way around if my level needs to access my Main Camera's "CutScene" Script?
Also say I want my Gun to access my player's Graphics's "ChangeColor" Script?
So mainly I want to know thoroughly how the parenting system works so I can take advantage of it's full potential.
The parent's parent is `transform.parent.parent`. Accessing "main camera" from "level" would be `transform.Find("Player/Main Camera")`.
Singleton s = transform.parent.parent.GetComponent("Singleton");
//OR transform.root.GetComponent("Singleton"); //if you know it will be the top-level object in the hierarchy always
CutScene cs = GetComponentInChildren("CutScene");
ChangeColor cc = GetComponentInChildren("ChangeColor");
using root for the first level hierarchy or recursively reading the child could work too, simple (untested) example:
Transform transforms = Selection.GetTransforms(Selection.Deep);
foreach(Transform t in transforms)
<p>print("hello, I'm " + t + ", I have " + t.childCount + " children");</p>