Fix PlayerSpawnController bug that sometimes caused player to spawn in wrong location

This commit is contained in:
2022-08-18 10:48:18 -07:00
parent dd4a4b1eb6
commit 6c513aafc7
3 changed files with 15 additions and 4 deletions

View File

@@ -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<PlayerSpawnController>().Except(new[] { this });
if (otherSpawnControllers.Any())
Destroy(this);
else
DontDestroyOnLoad(this);
}
private void Start()
{
if (GameObject.FindGameObjectWithTag("Player") != null)
{