- Home /
Can my script instantiate an object then get that object for use in the script
I have Ai and I want them to instantiate an object then I want them to find that object to use in their script
basically I am using a gameObject to control the ai movement but I want every ai to wove on they're own but I don't want to manually create an object for each ai (if there is a better way to do this then thanks)
Is this a new question, or was it answered by Nivbot? If not, please be more specific. Are the AIs GameObjects with their own scripts or they are all controlled by one script? If you have any code example, and what you want to achieve, then you can also post it here.
Answer by Nivbot · May 25, 2020 at 05:18 PM
If you instantiate an object you will already have a reference to it.
GameObject go = Instantiate(theObject);
go.GetComponent<FakeScript>();
that's all you have to do
It didn't work for my purpose but I am trying something else now