Re-think singleton player idea, add raycasting to stop from falling off ledges

This commit is contained in:
2022-08-15 15:40:04 -07:00
parent 4a4add3668
commit 9a245d94c7
23 changed files with 661 additions and 439 deletions

View File

@@ -7,18 +7,27 @@ namespace Scampz.GameJam.Assets.Scripts
{
public class BGMManager : MonoBehaviour
{
public static BGMManager Instance { get; private set; }
[SerializeField]
private AudioSource audioSource;
[SerializeField]
private AudioClip[] backgroundMusic;
private void Awake()
private static BGMManager _instance;
public static BGMManager Instance
{
if (Instance == null)
Instance = this;
get
{
if (!_instance)
{
_instance = new GameObject().AddComponent<BGMManager>();
_instance.name = _instance.GetType().ToString();
DontDestroyOnLoad(_instance.gameObject);
}
return _instance;
}
}
public void PlaySong()

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: f9f232ff3b526024b8abc7198b211a10
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: bcdc358652295014e9f9d90638ab5d0d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -12,14 +12,23 @@ namespace Scampz.GameJam
private TextMeshProUGUI dialogueTextGUI;
public float TextSpeed = 0.1f;
public static DialogueManager Instance { get; private set; }
public Queue<string> sentences;
private void Awake()
private static DialogueManager _instance;
public static DialogueManager Instance
{
if (Instance == null)
Instance = this;
get
{
if (!_instance)
{
_instance = new GameObject().AddComponent<DialogueManager>();
_instance.name = _instance.GetType().ToString();
DontDestroyOnLoad(_instance.gameObject);
}
return _instance;
}
}
public void Start()

View File

@@ -6,17 +6,24 @@ namespace Scampz.GameJam
{
public class GameManager : MonoBehaviour
{
public static GameManager Instance;
public Animator animator;
void Awake()
private static GameManager _instance;
public static GameManager Instance
{
if (Instance == null)
get
{
Instance = this;
if (!_instance)
{
_instance = new GameObject().AddComponent<GameManager>();
_instance.name = _instance.GetType().ToString();
DontDestroyOnLoad(_instance.gameObject);
}
return _instance;
}
}
void OnEnable()
{
//SceneManager.sceneLoaded += OnSceneLoaded;

View File

@@ -5,22 +5,28 @@ namespace Scampz.GameJam.Assets.Scripts
public class CharacterInputController : MonoBehaviour
{
private CharacterController _controller;
private RayCaster _caster;
public float Speed = 10f;
public float RotateSpeed = 1.0f;
private void Start()
{
_controller = GetComponent<CharacterController>();
_caster = _controller.GetComponent<RayCaster>();
}
void Update()
{
// Rotation
transform.Rotate(0, Input.GetAxis(InputOptions.Horizontal) * RotateSpeed, 0);
// Move
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = Speed * Input.GetAxis(InputOptions.Vertical);
_controller.SimpleMove(forward * curSpeed);
if (_caster.IsWithinBounds())
{
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = Speed * Input.GetAxis(InputOptions.Vertical);
_controller.SimpleMove(forward * curSpeed);
}
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 98567cc44adfaf2418a60d67d5fe5fb0
guid: 05cf47d54a6d28d47b5d9b54e95d2751
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,15 +0,0 @@
using UnityEngine;
namespace Scampz.GameJam.Assets.Scripts
{
public class InputManager : MonoBehaviour
{
public static InputManager Instance { get; private set; }
private void Awake()
{
if (Instance == null)
Instance = this;
}
}
}

View File

@@ -0,0 +1,22 @@
using UnityEngine;
namespace Scampz.GameJam.Assets.Scripts
{
public class RayCaster : MonoBehaviour
{
[SerializeField]
private float rayCastDistance = 1f;
public bool IsWithinBounds()
{
var offsetAngle = Quaternion.AngleAxis(45, transform.right);
return Physics.Raycast(transform.position, offsetAngle * transform.forward);
}
private void OnDrawGizmosSelected()
{
var offsetAngle = Quaternion.AngleAxis(45, transform.right);
Debug.DrawRay(transform.position, offsetAngle * transform.forward * rayCastDistance);
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: b39191ac21e3c3c46b862363cf286165
guid: e12a799f5a50bc34a94898baf2917b7b
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,13 +0,0 @@
using UnityEngine;
using UnityEngine.SceneManagement;
namespace Scampz.GameJam.Assets.Scripts
{
public class SingletonManager : MonoBehaviour
{
void Start()
{
GameManager.Instance.LoadScene(SceneNames.TempleA, LoadSceneMode.Single);
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 438ec7acec4f7004682b7953c3b96401
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: