Question by
danmoople · Apr 18, 2017 at 06:05 PM ·
unity 5scripting problemscript.unity 4.6unity 4.3
How to assign GameObject to Script?
I have a script with 2 gameobjects
Then I assign this script to an Instantiated object using Add.Component - but It's assigned with no gameobjects I need. Just "None (GameObject)". So how to assign those 2 gameobject to script before doing Add.Component to other gameobject?
1.png
(23.4 kB)
Comment
Best Answer
Answer by Cuttlas-U · Apr 18, 2017 at 06:13 PM
hi; u should assign GameObjects after Instantiate it;
on the start() method of your script create a function to search for those object by their name in the scene and add them;
for example :
void Start()
{
Road = GameObject.Find("Road");
Car= GameObject.Find("Car");
}