Files
blackhole-escape/Assets/Scripts/Other/DeadEngine.cs
iDunnoDev fb3415c7b2 Added new sounds needed for game
Added blackhole swirl texture and materials
Added Magnet, Hunter and Drop core powerups and script overhaul for powerups in general
Added Scenes and Cinematic changes for the game, win and death screens
Added a score
Changed the way enemy spawns work
Removed unused scripts
2022-07-14 17:31:10 +01:00

121 lines
3.3 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(10, '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();
}
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;
}
}
}
}