mirror of
https://github.com/Steffo99/keep-everything-alive.git
synced 2024-11-21 17:04:20 +00:00
Create game over scene
This commit is contained in:
parent
855ec29723
commit
81152a01ab
8 changed files with 162 additions and 12 deletions
|
@ -127,6 +127,26 @@ RectTransform:
|
||||||
type: 3}
|
type: 3}
|
||||||
m_PrefabInstance: {fileID: 903729141283580811}
|
m_PrefabInstance: {fileID: 903729141283580811}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
--- !u!1 &625994393 stripped
|
||||||
|
GameObject:
|
||||||
|
m_CorrespondingSourceObject: {fileID: 1475586332177117423, guid: 83b3c042c2cf3ce4fafc6b3346509ad9,
|
||||||
|
type: 3}
|
||||||
|
m_PrefabInstance: {fileID: 1475586331571591191}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
--- !u!114 &625994397
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 625994393}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 5083bec7e6907f844b7599d852b744c9, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
displayText: OVER
|
||||||
|
displayColor: {r: 1, g: 0, b: 0, a: 1}
|
||||||
--- !u!1 &706082052
|
--- !u!1 &706082052
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -307,6 +327,45 @@ RectTransform:
|
||||||
type: 3}
|
type: 3}
|
||||||
m_PrefabInstance: {fileID: 3646290606250593900}
|
m_PrefabInstance: {fileID: 3646290606250593900}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
--- !u!1 &1939693950 stripped
|
||||||
|
GameObject:
|
||||||
|
m_CorrespondingSourceObject: {fileID: 1475586332062904173, guid: 83b3c042c2cf3ce4fafc6b3346509ad9,
|
||||||
|
type: 3}
|
||||||
|
m_PrefabInstance: {fileID: 1475586331571591191}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
--- !u!114 &1939693954
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1939693950}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 5083bec7e6907f844b7599d852b744c9, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
displayText: GAME
|
||||||
|
displayColor: {r: 1, g: 0, b: 0, a: 1}
|
||||||
|
--- !u!1 &1959137559 stripped
|
||||||
|
GameObject:
|
||||||
|
m_CorrespondingSourceObject: {fileID: 3876737460387516449, guid: 83b3c042c2cf3ce4fafc6b3346509ad9,
|
||||||
|
type: 3}
|
||||||
|
m_PrefabInstance: {fileID: 1475586331571591191}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
--- !u!114 &1959137561
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1959137559}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 434b0b9680e8eb946ad858c56a075518, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
displayWhen: 2
|
||||||
--- !u!1001 &742014443134654871
|
--- !u!1001 &742014443134654871
|
||||||
PrefabInstance:
|
PrefabInstance:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
|
@ -28,6 +28,11 @@ public class GameController : MonoBehaviour
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public bool GameOver {
|
||||||
|
get {
|
||||||
|
return Lives <= 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[BeforeStart]
|
[BeforeStart]
|
||||||
public float startingTimescale = 1.0f;
|
public float startingTimescale = 1.0f;
|
||||||
|
@ -109,18 +114,21 @@ public class GameController : MonoBehaviour
|
||||||
|
|
||||||
private void OnMicrogameEnd(MicrogameController microgame, bool victory) {
|
private void OnMicrogameEnd(MicrogameController microgame, bool victory) {
|
||||||
Debug.Assert(microgame != null);
|
Debug.Assert(microgame != null);
|
||||||
if(victory) {
|
if(!victory) {
|
||||||
Score += 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Lives -= 1;
|
Lives -= 1;
|
||||||
}
|
}
|
||||||
|
Score += 1;
|
||||||
CurrentMicrogame = null;
|
CurrentMicrogame = null;
|
||||||
Faster();
|
if(!GameOver) {
|
||||||
StartCoroutine("SpinTheWheel");
|
if(score % increaseSpeedEvery == 0) {
|
||||||
|
Faster();
|
||||||
|
}
|
||||||
|
StartCoroutine("SpinTheWheel");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public float timescaleIncreaseFactor = 0.05f;
|
public float timescaleIncreaseFactor = 0.05f;
|
||||||
|
public float increaseSpeedEvery = 5;
|
||||||
private void Faster() {
|
private void Faster() {
|
||||||
Timescale += timescaleIncreaseFactor;
|
Timescale += timescaleIncreaseFactor;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,9 @@ public abstract class MicrogameController : MonoBehaviour
|
||||||
[BeforeStart]
|
[BeforeStart]
|
||||||
public Font microgameNameFont;
|
public Font microgameNameFont;
|
||||||
|
|
||||||
|
[Header("Microgame Results")]
|
||||||
|
public bool victory = true;
|
||||||
|
|
||||||
protected GameController gameController;
|
protected GameController gameController;
|
||||||
|
|
||||||
public delegate void OnTimeLeftChangeHandler(float previous, float current);
|
public delegate void OnTimeLeftChangeHandler(float previous, float current);
|
||||||
|
@ -44,8 +47,6 @@ public abstract class MicrogameController : MonoBehaviour
|
||||||
public delegate void OnMicrogameEndHandler(MicrogameController microgame, bool victory);
|
public delegate void OnMicrogameEndHandler(MicrogameController microgame, bool victory);
|
||||||
public event OnMicrogameEndHandler OnMicrogameEnd;
|
public event OnMicrogameEndHandler OnMicrogameEnd;
|
||||||
|
|
||||||
protected abstract bool MicrogameResults();
|
|
||||||
|
|
||||||
private void Awake() {
|
private void Awake() {
|
||||||
gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameController>();
|
gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameController>();
|
||||||
}
|
}
|
||||||
|
@ -56,7 +57,7 @@ public abstract class MicrogameController : MonoBehaviour
|
||||||
}
|
}
|
||||||
|
|
||||||
private void End() {
|
private void End() {
|
||||||
OnMicrogameEnd?.Invoke(this, MicrogameResults());
|
OnMicrogameEnd?.Invoke(this, victory);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update() {
|
private void Update() {
|
||||||
|
|
|
@ -4,7 +4,4 @@ using UnityEngine;
|
||||||
|
|
||||||
public class TestMicrogame : MicrogameController
|
public class TestMicrogame : MicrogameController
|
||||||
{
|
{
|
||||||
protected override bool MicrogameResults() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
35
Assets/Scripts/UI/DisplayOnGameOver.cs
Normal file
35
Assets/Scripts/UI/DisplayOnGameOver.cs
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
|
||||||
|
public enum DisplayOnGameOverOptions {
|
||||||
|
ALWAYS,
|
||||||
|
SHOW_ON_GAME_OVER,
|
||||||
|
HIDE_ON_GAME_OVER,
|
||||||
|
NEVER
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class DisplayOnGameOver : MonoBehaviour
|
||||||
|
{
|
||||||
|
public DisplayOnGameOverOptions displayWhen;
|
||||||
|
|
||||||
|
private GameController gameController;
|
||||||
|
private Text text;
|
||||||
|
|
||||||
|
private void Awake() {
|
||||||
|
gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameController>();
|
||||||
|
text = GetComponent<Text>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Start() {
|
||||||
|
gameController.OnGameOver += OnGameOver;
|
||||||
|
gameObject.SetActive(displayWhen == DisplayOnGameOverOptions.ALWAYS || displayWhen == DisplayOnGameOverOptions.HIDE_ON_GAME_OVER);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnGameOver(GameController sender) {
|
||||||
|
gameObject.SetActive(displayWhen == DisplayOnGameOverOptions.ALWAYS || displayWhen == DisplayOnGameOverOptions.SHOW_ON_GAME_OVER);
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Scripts/UI/DisplayOnGameOver.cs.meta
Normal file
11
Assets/Scripts/UI/DisplayOnGameOver.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 434b0b9680e8eb946ad858c56a075518
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
28
Assets/Scripts/UI/TextOnGameOver.cs
Normal file
28
Assets/Scripts/UI/TextOnGameOver.cs
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
[RequireComponent(typeof(Text))]
|
||||||
|
public class TextOnGameOver : MonoBehaviour
|
||||||
|
{
|
||||||
|
public string displayText;
|
||||||
|
public Color displayColor;
|
||||||
|
|
||||||
|
private GameController gameController;
|
||||||
|
private Text text;
|
||||||
|
|
||||||
|
private void Awake() {
|
||||||
|
gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameController>();
|
||||||
|
text = GetComponent<Text>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Start() {
|
||||||
|
gameController.OnGameOver += OnGameOver;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnGameOver(GameController sender) {
|
||||||
|
text.text = displayText;
|
||||||
|
text.color = displayColor;
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Scripts/UI/TextOnGameOver.cs.meta
Normal file
11
Assets/Scripts/UI/TextOnGameOver.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5083bec7e6907f844b7599d852b744c9
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in a new issue