Hey,
i have a big issue with understanding the organization of component and object organisation inside unity and how to access different things through script. I have to say i dont have a programmer background, so i am pretty new to C#… please be gentle ![]()
I have a Gameobject i want to use as a prefab which can be instanced through script later on. So i try to organize all its functions in a script i attach to the Gameobject.
you can see the hirarchy in the screenshot i attached. there is the 3d-modell, the infotext and the light. On the Gameobject itself there is a collider as a trigger.
Now i want to make some very easy things:
- on start the light and the text get disabled.
- when entering the trigger, i want to enable the text and the light.
so from what i have understood so far, every child-object of my “picture” is a gameobject for itself. Functions and Scripts are Components. Both can be enabled and disabled.
So, is it preferable to make a single script on the parent object, which tries to access all components of the child-object?
Or is it better to make little scipts on the child-objects, which the script on the parent-object is accessing?
In my Case:
do i make a light-script attached to the light, a text-script for the info-text both with public methods and a script on the picture-object which controlls the scripts on the childs?
i hope you get my point…
i try it like this but getting errors. Please help me to understand clean accessing of different parameters…
private GameObject infoText;
private Light myLight;
void Awake(){
myLight = Transform.Find ("Spotlight").GetComponent<Light> ();
infoText = Transform.Find ("Infotext");
}
