Fix World Camera

This commit is contained in:
2022-08-20 15:38:13 -07:00
parent 15a7e16650
commit 349c4dc4b6
26 changed files with 4085 additions and 2158 deletions

View File

@@ -1,5 +1,4 @@
using System.Collections;
using Scampz.GameJam.Assets.Scripts;
using UnityEngine;
using UnityEngine.SceneManagement;
@@ -8,7 +7,7 @@ namespace Scampz.GameJam
public class GameManager : MonoBehaviour
{
public static GameManager Instance;
private LevelChanger _levelChanger;
//private LevelChanger _levelChanger;
private void Awake()
{
@@ -19,16 +18,16 @@ namespace Scampz.GameJam
}
Instance = this;
_levelChanger = GetComponentInChildren<LevelChanger>();
//_levelChanger = GetComponentInChildren<LevelChanger>();
}
public void LoadScene(string sceneName, Transform spawnPoint, LoadSceneMode loadSceneMode)
public void LoadScene(string sceneName, LoadSceneMode loadSceneMode)
{
StartCoroutine(LoadSceneAsync(sceneName, spawnPoint, loadSceneMode));
StartCoroutine(LoadSceneAsync(sceneName, loadSceneMode));
}
private IEnumerator LoadSceneAsync(string sceneName, Transform spawnPoint, LoadSceneMode loadSceneMode)
private IEnumerator LoadSceneAsync(string sceneName, LoadSceneMode loadSceneMode)
{
yield return null;
var loadSceneOperation = SceneManager.LoadSceneAsync(sceneName, loadSceneMode);
@@ -42,19 +41,6 @@ namespace Scampz.GameJam
loadSceneOperation.allowSceneActivation = true;
yield return loadSceneOperation;
if (SceneManager.GetActiveScene().name == sceneName)
{
var player = GameObject.FindGameObjectWithTag("Player");
player.transform.position = spawnPoint.transform.position;
player.transform.rotation = spawnPoint.transform.rotation;
var camera = player.GetComponentInChildren<Camera>();
if (SceneManager.GetActiveScene().name == SceneNames.WorldMap)
camera.enabled = true;
else
camera.enabled = false;
}
}
}
}

View File

@@ -1,41 +1,19 @@
using System.Linq;
using UnityEngine;
public class PlayerSpawnController : MonoBehaviour
{
[SerializeField]
private GameObject _player;
public GameObject Player;
[SerializeField]
private GameObject _playerPrefab;
[SerializeField]
private GameObject _spawnLocation;
private void Awake()
{
var otherSpawnControllers = FindObjectsOfType<PlayerSpawnController>().Except(new[] { this });
if (otherSpawnControllers.Any())
Destroy(this);
else
DontDestroyOnLoad(this.gameObject);
}
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);
}
Player = Instantiate(_playerPrefab);
Player.transform.position = _spawnLocation.transform.position;
Player.transform.rotation = _spawnLocation.transform.rotation;
DontDestroyOnLoad(Player);
}
}