using System.Linq; using UnityEngine; public class PlayerSpawnController : MonoBehaviour { [SerializeField] private GameObject _player; [SerializeField] private GameObject _playerPrefab; [SerializeField] private GameObject _spawnLocation; 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) { _player = GameObject.FindGameObjectWithTag("Player"); _player.transform.position = _spawnLocation.transform.position; _player.transform.rotation = _spawnLocation.transform.rotation; } else { _player = Instantiate(_playerPrefab); _player.transform.position = _spawnLocation.transform.position; _player.transform.rotation = _spawnLocation.transform.rotation; DontDestroyOnLoad(_player); } } }