- Home /
How can I instantiate a player into a scene I just loaded in the same function
I have 2 buttons in a scene. Both have a similar script: using UnityEngine; using UnityEngine.SceneManagement; public class ArcherButton : MonoBehaviour { public GameObject archer; public void ArcherChosen() { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1); Instantiate(Archer); } } Issuse is that the function spawns the "archer" before the other scene is loaded, how could i tell it to instatiate the archer after the scene is loaded? Thanks for the answers =)
Answer by davidcox70 · Aug 05, 2020 at 10:49 PM
You need to instantiate your archer in a new script attached to a gameObject in the scene that you are loading. Put the instantiate call into the Start() function. Then it will instantiate in the new scene after it is fully loaded up.
Your answer
Follow this Question
Related Questions
Saving and loading level/game state 1 Answer
Checking if object intersects? 1 Answer
Coroutine executes unrelated object's code 0 Answers
OnTriggerEnter() not working 1 Answer
Loading Prefab from Script 1 Answer