Files
Scampz/Assets/Scripts/GameManager/WorldMapSpawnController.cs
Zenny 7a891a45f1 Add airship level
Fix default spawn issue
TODO: Fix issue with spawning when loading from other scenes
2022-08-30 01:48:01 -07:00

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;
}
}