Fix default spawn issue TODO: Fix issue with spawning when loading from other scenes
31 lines
970 B
C#
31 lines
970 B
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class WorldMapSpawnController : MonoBehaviour
|
|
{
|
|
[HideInInspector]
|
|
public GameObject Player;
|
|
[HideInInspector]
|
|
public Transform DefaultSpawnLocation;
|
|
[HideInInspector]
|
|
public List<Transform> SpawnLocations;
|
|
[SerializeField]
|
|
private GameObject _playerPrefab;
|
|
[SerializeField]
|
|
private Transform[] _spawnLocationsPrefabs;
|
|
[SerializeField]
|
|
private Transform _defaultSpawnLocationPrefab;
|
|
|
|
private void OnEnable()
|
|
{
|
|
Player = Instantiate(_playerPrefab);
|
|
DefaultSpawnLocation = Instantiate(_defaultSpawnLocationPrefab);
|
|
foreach (var spawnLocationPrefab in _spawnLocationsPrefabs)
|
|
SpawnLocations.Add(Instantiate(spawnLocationPrefab));
|
|
var cc = Player.GetComponent<CharacterController>();
|
|
cc.enabled = false;
|
|
Player.transform.position = DefaultSpawnLocation.position;
|
|
Player.transform.rotation = DefaultSpawnLocation.rotation;
|
|
cc.enabled = true;
|
|
}
|
|
} |