- Home /
Assign a GameObject to a Component Public Variable using c#
Hello, I have just added a GameObject to the scene and I would like to be able to control it. I have custom scripts written for the left and right controllers and I've attached these scripts to the left and right controllers within the SteamVR CameraRig. I need to assign "PitchingPanel_Om....." (the gameObject) to the variable of "cube" within the custom script. How might I be able to do this? Here's a picture. Also I cannot just click and drag because I have a few hundred of these- it needs to be via c# script.
As in I have a few hundred different scenes that I need to do this for.
Each scene has a different object to be controlled.
Answer by ZeN12 · Jul 17, 2017 at 02:28 PM
You can do it in runtime. Like in Awake method. Find object by tag.
Also I'm very new to unity, so just a little bit more explanation would be awesome.
Also, edit mode would be preferred I think. I have 100+ scenes for 100+ different objects.
Give each object a tag and in start method use
cube = GameObject.FindWithTag("yourtag");
I still don't see why you need 100 scenes, just use one scene and switch between controllers?