How to set a veriable in script

Hey currently struggling with my code.

public Transform target;

I want to set the target object in the script. Because I’m doing a wave system and when I spawn/instantiate the AI it doesn’t have the target set and just does what it’s not supposed to. And I want to do this all in one script.

All help is much appreciated!

Is the target the player?

If you setup the target variable on the spawning script, then you can pass a reference to any AI that you spawn, if they also have the ‘target’ variable on a script attached to them.

GameObject newSpawn = Instantiate(AIPrefab);
newSpawn.GetComponent<AIScript>().target = target;

That make sense?