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,33 +1,19 @@
using UnityEngine;
using UnityEngine.SceneManagement;
namespace Scampz.GameJam.Assets.Scripts.Audio
{
public class BGM : MonoBehaviour
{
[SerializeField]
private AudioClip[] backgroundMusic;
public AudioClip backgroundMusic;
public AudioClip GetClipFromSceneType(Scene scene)
private void OnTriggerEnter(Collider collider)
{
AudioClip audioClipToPlay = null;
if (scene.name.Contains("Temple"))
audioClipToPlay = backgroundMusic[0];
if (scene.name.Contains("Sanctum"))
audioClipToPlay = backgroundMusic[1];
if (scene.name.Contains("Snow"))
audioClipToPlay = backgroundMusic[2];
if (scene.name.Equals("SnowC"))
audioClipToPlay = backgroundMusic[3];
if (scene.name.Contains("Airship"))
audioClipToPlay = backgroundMusic[4];
if (scene.name.Equals("AirshipInside"))
audioClipToPlay = backgroundMusic[5];
if (scene.name.Contains("Void"))
audioClipToPlay = backgroundMusic[6];
return audioClipToPlay;
if (collider.CompareTag("Player"))
{
var bgmManager = FindObjectOfType<BGMManager>();
bgmManager.PlayBGM(backgroundMusic);
}
}
}
}

View File

@@ -1,16 +1,10 @@
using Scampz.GameJam.Assets.Scripts.Audio;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine;
namespace Scampz.GameJam.Assets.Scripts
{
[RequireComponent(typeof(AudioSource))]
public class BGMManager : MonoBehaviour
{
[SerializeField]
private BGM _backgroundMusic;
private static AudioSource _audioSource;
private void Awake()
@@ -21,47 +15,11 @@ namespace Scampz.GameJam.Assets.Scripts
_audioSource.loop = true;
DontDestroyOnLoad(_audioSource.gameObject);
}
if (_backgroundMusic == null)
{
Instantiate(_backgroundMusic);
DontDestroyOnLoad(_backgroundMusic.gameObject);
}
}
private void OnEnable()
{
SceneManager.activeSceneChanged += PlayNextSongIfAreaChange;
}
private void OnDisable()
{
SceneManager.activeSceneChanged -= PlayNextSongIfAreaChange;
}
private void PlayNextSongIfAreaChange(Scene oldScene, Scene newScene)
{
if (_audioSource.clip == null)
{
var newMusic = _backgroundMusic.GetClipFromSceneType(newScene);
PlayBGM(newMusic);
return;
}
Debug.Log($"Changed scenes to " + newScene.name);
var newAudioClip = _backgroundMusic.GetClipFromSceneType(newScene);
if (_audioSource.clip.name != newAudioClip.name)
{
PlayBGM(newAudioClip);
}
Debug.Log($"Playing BGM: " + _backgroundMusic.name);
}
public void PlayBGM(AudioClip audioClip)
{
if (_audioSource == null && _audioSource.clip == audioClip)
if (_audioSource == null || _audioSource.clip == audioClip)
return;
_audioSource.Stop();

View File

@@ -26,7 +26,8 @@ namespace Scampz.GameJam.Assets.Scripts.Audio
public void PlaySoundEffect(string soundEffect)
{
var audioClip = GetClipFromName(soundEffect);
_audioSource.PlayOneShot(audioClip);
_audioSource.clip = audioClip;
_audioSource.Play();
}
public void StopSoundEffect()

View File

@@ -1,4 +1,3 @@
using System;
using UnityEngine;
namespace Scampz.GameJam
@@ -13,20 +12,19 @@ namespace Scampz.GameJam
private float smoothFactor = 0.5f;
[SerializeField]
private bool lookAtTarget = false;
[SerializeField]
private float _cameraYPosition = 45f;
private void Start()
{
//cameraOffset = transform.position - targetObject.transform.position;
transform.position = targetObject.transform.position - cameraOffset;
}
private void LateUpdate()
{
if (lookAtTarget)
transform.LookAt(targetObject);
var newPosition = targetObject.transform.position + cameraOffset;
var absTransform = new Vector3(newPosition.x, Math.Abs(newPosition.y), newPosition.z);
transform.position = Vector3.Slerp(transform.position, newPosition, smoothFactor);
var lockedInYPosition = new Vector3(targetObject.transform.position.x - cameraOffset.x, _cameraYPosition, targetObject.transform.position.z - cameraOffset.z);
transform.position = lockedInYPosition;
transform.LookAt(transform);
}
}
}

View File

@@ -7,8 +7,7 @@ namespace Scampz.GameJam
{
[TextArea(3, 10)]
public string[] Sentences;
[SerializeField]
public SFXClip SoundEffect;
public float TextSpeed;
}
}

View File

@@ -16,11 +16,6 @@ namespace Scampz.GameJam
private Animator _animator;
[SerializeField]
private TextMeshProUGUI _dialogueTextGUI;
[SerializeField]
private float _defaultTextSpeed = 0.1f;
private float _currentTextSpeed;
private Queue<string> sentences;
@@ -48,8 +43,6 @@ namespace Scampz.GameJam
{
if (IsTalking && Input.GetButtonDown(InputOptions.Cancel))
EndDialogue();
_currentTextSpeed = _defaultTextSpeed;
}
public void StartDialogue(Dialogue dialogue)
@@ -93,10 +86,12 @@ namespace Scampz.GameJam
{
_dialogueTextGUI.text += letter;
yield return null;
yield return new WaitForSeconds(_currentTextSpeed);
yield return new WaitForSeconds(dialogue.TextSpeed);
}
yield return new WaitForSeconds(1f);
yield return null;
SFXManager.Instance.StopSoundEffect();
yield return new WaitForSeconds(0.3f);
yield return new WaitForKeyDown(InputOptions.Submit);
SFXManager.Instance.PlaySoundEffect(SoundEffectName.Ok);
DisplayNextSentence(dialogue);
@@ -104,6 +99,7 @@ namespace Scampz.GameJam
private void EndDialogue()
{
StopAllCoroutines();
_animator.SetBool("IsOpen", false);
_dialogueTextGUI.text = string.Empty;
IsTalking = false;

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

View File

@@ -13,12 +13,6 @@ namespace Scampz.GameJam.Assets.Scripts
private float currentHitDistance;
//public bool IsWithinBounds()
//{
// var offsetAngle = Quaternion.AngleAxis(rayCastAngle, transform.right);
// return Physics.Raycast(transform.position, offsetAngle * transform.forward);
//}
public bool IsWithinBounds()
{
var offsetAngleRight = Quaternion.AngleAxis(rayCastAngle, transform.right);

View File

@@ -0,0 +1,21 @@
using UnityEngine;
namespace Scampz.GameJam.Assets.Scripts
{
public class UseGroundChecking : MonoBehaviour
{
[SerializeField]
private bool useGroundChecking;
private void OnTriggerEnter(Collider collider)
{
if (collider.CompareTag("Player"))
{
var playerSpawnController = FindObjectOfType<PlayerSpawnController>();
var player = playerSpawnController.Player;
var rayCaster = player.GetComponent<RayCaster>();
rayCaster.enabled = useGroundChecking;
}
}
}
}

View File

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

View File

@@ -22,7 +22,8 @@ namespace Scampz.GameJam.Assets.Scripts.Player
private void Update()
{
_animator.SetFloat("Speed", _characterController.velocity.magnitude);
_canMove = _rayCaster.IsWithinBounds();
if (_rayCaster.enabled)
_canMove = _rayCaster.IsWithinBounds();
}
public bool CanMove => _canMove;

View File

@@ -8,19 +8,13 @@ namespace Scampz.GameJam
private bool loaded = false;
[SerializeField]
private string scene;
[SerializeField]
private Transform _spawnPoint;
void OnTriggerEnter(Collider collider)
{
if (!loaded && collider.CompareTag("Player"))
{
loaded = true;
var player = GameObject.FindGameObjectWithTag("Player");
var cc = player.GetComponent<CharacterController>();
cc.enabled = false;
GameManager.Instance.LoadScene(scene, _spawnPoint, LoadSceneMode.Single);
cc.enabled = true;
GameManager.Instance.LoadScene(scene, LoadSceneMode.Single);
}
}
}

View File

@@ -10,7 +10,7 @@ namespace Scampz.GameJam
{
if (Input.GetButtonDown(InputOptions.Submit))
{
GameManager.Instance.LoadScene(SceneNames.TempleA, transform, LoadSceneMode.Single);
GameManager.Instance.LoadScene(SceneNames.TempleA, LoadSceneMode.Single);
}
}
}