Add SFX to dialogue, revamp control scheme (broken world map camera)

This commit is contained in:
2022-08-17 22:12:53 -07:00
parent 294b113598
commit bc8092d454
29 changed files with 1413 additions and 485 deletions

View File

@@ -1,8 +0,0 @@
using UnityEngine;
namespace Scampz.GameJam
{
public class AudioPlayer : MonoBehaviour
{
}
}

View File

@@ -0,0 +1,9 @@
using UnityEngine;
namespace Scampz.GameJam.Assets.Scripts.Audio
{
public class SFX : MonoBehaviour
{
public AudioClip[] SoundEffects;
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 0929d89c738f7434a8aeb4a3142ae89d
guid: d4470fbab6987df4baea8aa8b9b42f6b
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -0,0 +1,64 @@
using System.Linq;
using UnityEngine;
namespace Scampz.GameJam.Assets.Scripts.Audio
{
public class SFXManager : MonoBehaviour
{
public static SFXManager Instance;
[SerializeField]
private SFX _soundEffects;
[SerializeField]
private AudioSource _audioSource;
private void Awake()
{
if (Instance != null && Instance != this)
{
Destroy(this);
return;
}
Instance = this;
}
public void PlaySoundEffect(string soundEffect)
{
var audioClip = GetClipFromName(soundEffect);
_audioSource.PlayOneShot(audioClip);
}
public void StopSoundEffect()
{
_audioSource.Stop();
}
private AudioClip GetClipFromName(string desiredSoundEffect)
=> _soundEffects.SoundEffects.Where(x => x.name.Equals(desiredSoundEffect)).Single();
}
public class SoundEffect
{
public static string ComputerTalk => "computer talk ed";
public static string Diety => "diety";
public static string LavaGuy => "lava guy ed";
public static string MenuUpDown => "menu up down";
public static string Narration => "narration";
public static string Ok => "ok";
public static string SandStep => "sand step ed";
public static string SnowStep => "snow step";
public static string TempleStep => "temple step ed";
public static string GrassStep => "grass step ed";
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: bd3e63ea94a97734bbe89a8d50059585
guid: d1081614305b95943acf23b2a69bbc20
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -0,0 +1,30 @@
using UnityEngine;
namespace Scampz.GameJam
{
public class CameraFollow : MonoBehaviour
{
[SerializeField]
private Transform targetObject;
[SerializeField]
private Vector3 cameraOffset;
[SerializeField]
private float smoothFactor = 0.5f;
[SerializeField]
private bool lookAtTarget = false;
private void Start()
{
cameraOffset = transform.position - targetObject.transform.position;
}
private void LateUpdate()
{
if (lookAtTarget)
transform.LookAt(targetObject);
var newPosition = targetObject.transform.position + cameraOffset;
transform.position = Vector3.Slerp(transform.position, newPosition, smoothFactor);
}
}
}

View File

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

View File

@@ -1,8 +0,0 @@
using UnityEngine;
namespace Scampz.GameJam
{
public class DialogueInteraction : MonoBehaviour
{
}
}

View File

@@ -2,6 +2,7 @@ using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Scampz.GameJam.Assets.Scripts;
using Scampz.GameJam.Assets.Scripts.Audio;
using Scampz.GameJam.Assets.Scripts.Utilities;
using TMPro;
using UnityEngine;
@@ -64,6 +65,8 @@ namespace Scampz.GameJam
return;
}
SFXManager.Instance.PlaySoundEffect(SoundEffect.Narration);
var sentence = sentences.Dequeue();
StopAllCoroutines();
StartCoroutine(TypeSentence(sentence));
@@ -80,7 +83,11 @@ namespace Scampz.GameJam
yield return new WaitForSecondsRealtime(_textSpeed);
}
yield return new WaitForSecondsRealtime(1f);
SFXManager.Instance.StopSoundEffect();
yield return new WaitForKeyDown(InputOptions.Submit);
SFXManager.Instance.PlaySoundEffect(SoundEffect.Ok);
yield return new WaitForSeconds(0.5f);
DisplayNextSentence();
}
@@ -88,6 +95,7 @@ namespace Scampz.GameJam
{
_animator.SetBool("IsOpen", false);
IsTalking = false;
SFXManager.Instance.StopSoundEffect();
}
}
}

View File

@@ -1,4 +1,5 @@
using System.Collections;
using Scampz.GameJam.Assets.Scripts;
using UnityEngine;
using UnityEngine.SceneManagement;
@@ -29,7 +30,6 @@ namespace Scampz.GameJam
private IEnumerator LoadSceneAsync(string sceneName, Transform spawnPoint, LoadSceneMode loadSceneMode)
{
Debug.Log("Start Level Load");
yield return null;
var loadSceneOperation = SceneManager.LoadSceneAsync(sceneName, loadSceneMode);
loadSceneOperation.allowSceneActivation = false;
@@ -43,14 +43,17 @@ namespace Scampz.GameJam
loadSceneOperation.allowSceneActivation = true;
yield return loadSceneOperation;
Debug.Log("Stop Level Load");
if (SceneManager.GetActiveScene().name == sceneName)
{
Debug.Log("Move Player");
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

@@ -7,7 +7,7 @@ namespace Scampz.GameJam.Assets.Scripts
private CharacterController _controller;
private RayCaster _caster;
public float Speed = 10f;
public float RotateSpeed = 1.0f;
public float RotateSpeed = 720.0f;
private void Start()
{
@@ -17,15 +17,16 @@ namespace Scampz.GameJam.Assets.Scripts
void Update()
{
// Rotation
transform.Rotate(0, Input.GetAxis(InputOptions.Horizontal) * RotateSpeed, 0);
var direction = new Vector3(Input.GetAxisRaw(InputOptions.Horizontal), 0, Input.GetAxisRaw(InputOptions.Vertical)).normalized;
// Move
if (_caster.IsWithinBounds())
_controller.SimpleMove(-direction * Speed);
if (direction != Vector3.zero)
{
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = Speed * Input.GetAxis(InputOptions.Vertical);
_controller.SimpleMove(forward * curSpeed);
var toRotation = Quaternion.LookRotation(-direction, Vector3.up);
transform.rotation = Quaternion.RotateTowards(transform.rotation, toRotation, RotateSpeed);
}
}
}

View File

@@ -2,6 +2,8 @@
{
public static class SceneNames
{
public static string Singleton => "Singleton";
public static string TempleA => "TempleA";
public static string WorldMap => "WorldMap";
}
}

View File

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