From 6c513aafc7095d02604bcd7a1a047447ca050272 Mon Sep 17 00:00:00 2001 From: Zenny Date: Thu, 18 Aug 2022 10:48:18 -0700 Subject: [PATCH] Fix PlayerSpawnController bug that sometimes caused player to spawn in wrong location --- Assets/Scenes/Temple/TempleB.unity | 4 ++-- Assets/Scripts/GameManager/PlayerSpawnController.cs | 13 ++++++++++++- Assets/SpawnPoints/Temple C To Temple B.prefab | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Assets/Scenes/Temple/TempleB.unity b/Assets/Scenes/Temple/TempleB.unity index e29624e..e79de68 100644 --- a/Assets/Scenes/Temple/TempleB.unity +++ b/Assets/Scenes/Temple/TempleB.unity @@ -312,7 +312,7 @@ MeshRenderer: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 455432347} - m_Enabled: 1 + m_Enabled: 0 m_CastShadows: 1 m_ReceiveShadows: 1 m_DynamicOccludee: 1 @@ -1383,7 +1383,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 7190262219221540737, guid: b273c0298305ae84e9a55d1de630edc0, type: 3} propertyPath: m_LocalPosition.y - value: 24.68 + value: 23 objectReference: {fileID: 0} - target: {fileID: 7190262219221540737, guid: b273c0298305ae84e9a55d1de630edc0, type: 3} propertyPath: m_LocalPosition.z diff --git a/Assets/Scripts/GameManager/PlayerSpawnController.cs b/Assets/Scripts/GameManager/PlayerSpawnController.cs index 6a121c0..9b9d87a 100644 --- a/Assets/Scripts/GameManager/PlayerSpawnController.cs +++ b/Assets/Scripts/GameManager/PlayerSpawnController.cs @@ -1,3 +1,4 @@ +using System.Linq; using UnityEngine; public class PlayerSpawnController : MonoBehaviour @@ -9,7 +10,17 @@ public class PlayerSpawnController : MonoBehaviour [SerializeField] private GameObject _spawnLocation; - void Awake() + + private void Awake() + { + var otherSpawnControllers = FindObjectsOfType().Except(new[] { this }); + if (otherSpawnControllers.Any()) + Destroy(this); + else + DontDestroyOnLoad(this); + } + + private void Start() { if (GameObject.FindGameObjectWithTag("Player") != null) { diff --git a/Assets/SpawnPoints/Temple C To Temple B.prefab b/Assets/SpawnPoints/Temple C To Temple B.prefab index a87cc9b..5abafad 100644 --- a/Assets/SpawnPoints/Temple C To Temple B.prefab +++ b/Assets/SpawnPoints/Temple C To Temple B.prefab @@ -27,7 +27,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7190262219221540742} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 26.18, y: 24.68, z: -18.753551} + m_LocalPosition: {x: 26.18, y: 23, z: -18.753551} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: []