Im fairly new to Unity. I finished the FPS tutorial and am trying to spawn a Robot every second at a spawn point. The problem is, when I spawn them they are doing nothing because they do not have a target set.
I am scripting this modification in C#, and I am unsure how to set the target for each robot instance after instantiating it.
I tried GetComponent(“AI”) with no luck. AI being the js script that has the variable for the target.
If you’re using Instantiate to create your robots, then you probably want to use the value returned by Instantiate. If you’re instantiating a prefab with a script called “AI” attached, you need something like this:
Hi. I’ve been struggling to get this to work, maybe you can help.
I have 2 scripts: one that spawns enemies (enemySpawner.js) and one that has AI (enemyAI.js).
The spawn script is on a gizmo that’s in the level (hierarchy). The AI script is on the enemy prefab in the project viewer.
The AI script has variable ‘leader’ that should point to the player prefab when instantiated. I also gave the player prefab the tag of ‘Player’.
So this is what my spawn script looks like: