Add airship level
Fix default spawn issue TODO: Fix issue with spawning when loading from other scenes
This commit is contained in:
@@ -19,17 +19,12 @@ namespace Scampz.GameJam
|
||||
}
|
||||
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
public void LoadFromWorldMap(LoadSceneMode loadSceneMode)
|
||||
{
|
||||
SceneManager.LoadScene("WorldMap", loadSceneMode);
|
||||
}
|
||||
|
||||
private IEnumerator LoadSceneAsync(string sceneName, Transform spawnPoint, LoadSceneMode loadSceneMode)
|
||||
private IEnumerator LoadSceneAsync(string sceneName, LoadSceneMode loadSceneMode)
|
||||
{
|
||||
yield return null;
|
||||
var player = GameObject.FindGameObjectWithTag("Player");
|
||||
@@ -51,8 +46,6 @@ namespace Scampz.GameJam
|
||||
yield return loadSceneOperation;
|
||||
var cc = player.GetComponent<CharacterController>();
|
||||
cc.enabled = false;
|
||||
player.transform.position = spawnPoint.position;
|
||||
player.transform.rotation = spawnPoint.rotation;
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerSpawnController : MonoBehaviour
|
||||
public partial class PlayerSpawnController : MonoBehaviour
|
||||
{
|
||||
public GameObject Player;
|
||||
[SerializeField]
|
||||
@@ -14,5 +14,4 @@ public class PlayerSpawnController : MonoBehaviour
|
||||
Player.transform.position = _spawnLocation.transform.position;
|
||||
Player.transform.rotation = _spawnLocation.transform.rotation;
|
||||
}
|
||||
|
||||
}
|
||||
31
Assets/Scripts/GameManager/WorldMapSpawnController.cs
Normal file
31
Assets/Scripts/GameManager/WorldMapSpawnController.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/GameManager/WorldMapSpawnController.cs.meta
Normal file
11
Assets/Scripts/GameManager/WorldMapSpawnController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab97fce054425504e9f8c78312d1081d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -9,6 +9,7 @@ namespace Scampz.GameJam.Assets.Scripts.Player
|
||||
private bool _canMove;
|
||||
private GameObject _player;
|
||||
private CharacterController _characterController;
|
||||
public string SceneName;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
@@ -24,6 +25,9 @@ namespace Scampz.GameJam.Assets.Scripts.Player
|
||||
var rayCasterExists = TryGetComponent<RayCaster>(out var rayCaster);
|
||||
if (SceneManager.GetActiveScene().name.Equals("WorldMap") && rayCasterExists)
|
||||
_canMove = rayCaster.IsWithinBoundsWithRay();
|
||||
|
||||
if (SceneName != string.Empty && SceneName != "WorldMap")
|
||||
SceneName = SceneManager.GetActiveScene().name;
|
||||
}
|
||||
|
||||
public bool CanMove => _canMove;
|
||||
|
||||
@@ -11,8 +11,6 @@ namespace Scampz.GameJam
|
||||
[SerializeField]
|
||||
private string _scene;
|
||||
[SerializeField]
|
||||
private Transform _spawnPoint;
|
||||
[SerializeField]
|
||||
private bool _promptToEnter;
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _promptText;
|
||||
@@ -31,7 +29,7 @@ namespace Scampz.GameJam
|
||||
|
||||
private void OnTriggerStay(Collider collider)
|
||||
{
|
||||
if (!_loaded && collider.CompareTag("Player") && _promptText != null && _promptText.enabled && Input.GetButtonDown(InputOptions.Submit))
|
||||
if (!_loaded && collider.CompareTag("Player") && _promptText != null && _promptText.enabled && Input.GetButton(InputOptions.Submit))
|
||||
LoadNextLevel();
|
||||
}
|
||||
|
||||
@@ -44,7 +42,7 @@ namespace Scampz.GameJam
|
||||
private void LoadNextLevel()
|
||||
{
|
||||
_loaded = true;
|
||||
GameManager.Instance.LoadScene(_scene, _spawnPoint, LoadSceneMode.Single);
|
||||
GameManager.Instance.LoadScene(_scene, LoadSceneMode.Single);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,8 @@ namespace Scampz.GameJam
|
||||
{
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetButtonDown(InputOptions.Submit))
|
||||
{
|
||||
GameManager.Instance.LoadFromWorldMap(LoadSceneMode.Single);
|
||||
}
|
||||
if (Input.GetButton(InputOptions.Submit))
|
||||
GameManager.Instance.LoadScene(SceneNames.WorldMap, LoadSceneMode.Single);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user