Files
blackhole-escape/Assets/Scripts/Other/DeadEngine.cs
iDunnoDev 62254a0332 Updated Unity Version
Added graphics options and rendering quality level settings
Added new movement patterns to the dumb enemy AI
Added chance for Coward Enemies to drop a random
Added method to correctly reset the game variables on death and win screens
Updated the UI to work on different resolutions without breaking
Moved Sprites into a sprites folder
Fixed issue where score would overflow the int because the multiplier was too high
Fixed issue where new lives gained from the score breakpoints were not being calculated correctly
Fixed issue where clicking off a menu element then trying to control the menu with the controller did not correctly reselect a menu item
Fixed issue where enemies colliding with the outer boundary too much would break the sfx and music (i assume from a buffering issue)
2022-07-23 14:43:52 +01:00

122 lines
3.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
public class DeadEngine : MonoBehaviour
{
public GameObject hudGO;
public GameObject cockpitGO;
public TMPro.TextMeshProUGUI scoreText;
public float cockpitRotationSpeed;
public BackgroundMusicManager currentBGMManager;
public MenuAudioManager currentMenuAudioManager;
public float flashFrequencyTime;
private TimerHelper _flashTimer;
private MeshRenderer _meshRenderer;
private Color _defaultEmissionColor;
private GameObject _lastControlSelected;
private void Awake()
{
GameManager.Instance.currentGameState = GameState.DEATHMENU;
}
// Start is called before the first frame update
void Start()
{
// If the BGM manager is present, queue up and play the given track index
if (currentBGMManager)
{
currentBGMManager.StartAudioQueueAndPlay(0);
}
_flashTimer = new TimerHelper(flashFrequencyTime);
_meshRenderer = hudGO.GetComponent<MeshRenderer>();
_defaultEmissionColor = _meshRenderer.materials[0].GetColor("_EmissionColor");
_lastControlSelected = EventSystem.current.firstSelectedGameObject;
scoreText.text = scoreText.text.Replace("{SCORE}", GameManager.Instance.CurrentScore.ToString().PadLeft(9, '0'));
}
public void PlayMenuClick()
{
if (currentMenuAudioManager)
{
currentMenuAudioManager.PlayMenuClick();
}
}
public void MainMenuNav()
{
// Play the menu click sound if the audio manager is present
if (currentMenuAudioManager)
{
currentMenuAudioManager.PlayMenuClick();
}
SceneManager.LoadSceneAsync("MainMenu");
}
public void GameMenuNav()
{
// Play the menu click sound if the audio manager is present
if (currentMenuAudioManager)
{
currentMenuAudioManager.PlayMenuClick();
}
GameManager.Instance.ResetStats();
SceneManager.LoadSceneAsync("Game");
}
public void Quit()
{
// Play the menu click sound if the audio manager is present
if (currentMenuAudioManager)
{
currentMenuAudioManager.PlayMenuClick();
}
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
}
// Update is called once per frame
void Update()
{
if (cockpitGO != null)
{
cockpitGO.transform.Rotate(Vector3.up, cockpitRotationSpeed * Time.deltaTime);
}
if (_flashTimer.HasTicked(Time.deltaTime))
{
float randomNo = Random.Range(0.0f, 1.0f);
_meshRenderer.materials[0].SetColor("_EmissionColor", Color.Lerp(Color.black, _defaultEmissionColor, randomNo));
}
float horzIn = Input.GetAxis("Horizontal");
float vertIn = Input.GetAxis("Vertical");
if (horzIn != 0 || vertIn != 0)
{
if (EventSystem.current.currentSelectedGameObject == null)
{
EventSystem.current.SetSelectedGameObject(_lastControlSelected);
}
else
{
_lastControlSelected = EventSystem.current.currentSelectedGameObject;
}
}
}
}