- Home /
Question by
iAintGotMoney · Apr 21 at 09:45 PM ·
scripting problemscripting beginner
How do I change a public Transform with a script before spawning a prefab?
Hey, so I have tried making it so when the enemy spawns it goes towards the player. The enemy is a prefab in a prefabs folder. This is called in a coroutine that is called. So far I have this:
IEnumerator doMoreStuff()
{
yield return new WaitForSeconds(10);
var alien = Instantiate(myAlien, new Vector2(spawnPos.position.x, spawnPos.position.y), Quaternion.identity);
player = GameObject.Find("Player").transform; // This is where I'm trying to change it btw
DoStuff();
}
It's not changing the transform. Please can someone help?
Thanks!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613055655im_/https://answers.unity.com/themes/thub/images/avi.jpg)