Forum begins after the advertisement:
[Part 6] Trying to spawn the player in a randomly generated map
Home › Forums › Video Game Tutorial Series › Creating a Rogue-like Shoot-em Up in Unity › [Part 6] Trying to spawn the player in a randomly generated map
- This topic has 27 replies, 2 voices, and was last updated 11 months, 1 week ago by
Terence.
-
AuthorPosts
-
September 20, 2024 at 3:34 pm #15867::
yes ofcourse,
private void OnSceneLoaded(Scene scene, LoadSceneMode mode) { Debug.Log("OnSceneLoaded called for scene: " + scene.name); WalkerGenerator walkerGenerator = FindFirstObjectByType<WalkerGenerator>(); if (walkerGenerator != null) { walkerGenerator.SpawnPlayer(); Debug.Log("WalkerGenerator found and SpawnPlayer called."); } else { Debug.LogError("WalkerGenerator not found in the scene."); } EnemySpawner enemySpawner = FindFirstObjectByType<EnemySpawner>(); if (enemySpawner != null) { enemySpawner.InitializeSpawner(); } else { Debug.LogError("EnemySpawner not found in the scene."); } }
September 21, 2024 at 12:05 am #15868September 23, 2024 at 3:38 pm #15902::when i click on the highlighted error message it takes me too my sceneloader script instead of the walkergenerator script
all the other errors also take me to other scripts than walkergenerator
View post on imgur.com
September 23, 2024 at 4:46 pm #15903::The first error says to add a WalkerGenerator component to your Scene. Maybe you can try that first.
September 24, 2024 at 3:48 pm #15912September 24, 2024 at 4:01 pm #15913::You can try delaying
OnSceneLoaded()
by a single frame and see if the WalkerGenerator can be found like this. The function may be running before your GameObjects are properly initialised:private IEnumerator OnSceneLoadedDelayed(Scene scene, LoadSceneMode mode) { Debug.Log("OnSceneLoaded called for scene: " + scene.name); WalkerGenerator walkerGenerator = FindFirstObjectByType<WalkerGenerator>(); if (walkerGenerator != null) { walkerGenerator.SpawnPlayer(); Debug.Log("WalkerGenerator found and SpawnPlayer called."); } else { Debug.LogError("WalkerGenerator not found in the scene."); } EnemySpawner enemySpawner = FindFirstObjectByType<EnemySpawner>(); if (enemySpawner != null) { enemySpawner.InitializeSpawner(); } else { Debug.LogError("EnemySpawner not found in the scene."); } } private void OnSceneLoaded(Scene scene, LoadSceneMode mode) { StartCoroutine(OnSceneLoadedDelayed(scene, mode)); }
The reason why I’m focusing on fixing the
WalkerGenerator
first is because it may be causing the other errors.September 24, 2024 at 5:20 pm #15915::the walkergenerator error is now gone. i still have a lot of errors though
i’ll also post a video of the layout of the scenes i have in the game so you can see when the errors appear
View post on imgur.com
September 25, 2024 at 9:43 pm #15923 -
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: