Added quick game timer
This commit is contained in:
parent
3d804d9f44
commit
25a10047ad
@ -1,5 +1,152 @@
|
|||||||
%YAML 1.1
|
%YAML 1.1
|
||||||
%TAG !u! tag:unity3d.com,2011:
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!1 &344214375
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 344214376}
|
||||||
|
- component: {fileID: 344214379}
|
||||||
|
- component: {fileID: 344214378}
|
||||||
|
- component: {fileID: 344214377}
|
||||||
|
m_Layer: 5
|
||||||
|
m_Name: Timer
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!224 &344214376
|
||||||
|
RectTransform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 344214375}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 1878107874060227351}
|
||||||
|
m_RootOrder: 2
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
m_AnchorMin: {x: 0, y: 1}
|
||||||
|
m_AnchorMax: {x: 0, y: 1}
|
||||||
|
m_AnchoredPosition: {x: 10, y: -40}
|
||||||
|
m_SizeDelta: {x: 200, y: 50}
|
||||||
|
m_Pivot: {x: 0, y: 1}
|
||||||
|
--- !u!114 &344214379
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 344214375}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: a53670f9cd399ea4a8ae3ed81b923aa8, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
--- !u!222 &344214378
|
||||||
|
CanvasRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 344214375}
|
||||||
|
m_CullTransparentMesh: 1
|
||||||
|
--- !u!114 &344214377
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 344214375}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
m_Material: {fileID: 0}
|
||||||
|
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
m_RaycastTarget: 1
|
||||||
|
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||||
|
m_Maskable: 1
|
||||||
|
m_OnCullStateChanged:
|
||||||
|
m_PersistentCalls:
|
||||||
|
m_Calls: []
|
||||||
|
m_text: 00:00
|
||||||
|
m_isRightToLeft: 0
|
||||||
|
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
|
||||||
|
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
|
||||||
|
m_fontSharedMaterials: []
|
||||||
|
m_fontMaterial: {fileID: 0}
|
||||||
|
m_fontMaterials: []
|
||||||
|
m_fontColor32:
|
||||||
|
serializedVersion: 2
|
||||||
|
rgba: 4278190080
|
||||||
|
m_fontColor: {r: 0, g: 0, b: 0, a: 1}
|
||||||
|
m_enableVertexGradient: 0
|
||||||
|
m_colorMode: 3
|
||||||
|
m_fontColorGradient:
|
||||||
|
topLeft: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
topRight: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
bottomRight: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
m_fontColorGradientPreset: {fileID: 0}
|
||||||
|
m_spriteAsset: {fileID: 0}
|
||||||
|
m_tintAllSprites: 0
|
||||||
|
m_StyleSheet: {fileID: 0}
|
||||||
|
m_TextStyleHashCode: -1183493901
|
||||||
|
m_overrideHtmlColors: 0
|
||||||
|
m_faceColor:
|
||||||
|
serializedVersion: 2
|
||||||
|
rgba: 4294967295
|
||||||
|
m_fontSize: 36
|
||||||
|
m_fontSizeBase: 36
|
||||||
|
m_fontWeight: 400
|
||||||
|
m_enableAutoSizing: 0
|
||||||
|
m_fontSizeMin: 18
|
||||||
|
m_fontSizeMax: 72
|
||||||
|
m_fontStyle: 0
|
||||||
|
m_HorizontalAlignment: 1
|
||||||
|
m_VerticalAlignment: 256
|
||||||
|
m_textAlignment: 65535
|
||||||
|
m_characterSpacing: 0
|
||||||
|
m_wordSpacing: 0
|
||||||
|
m_lineSpacing: 0
|
||||||
|
m_lineSpacingMax: 0
|
||||||
|
m_paragraphSpacing: 0
|
||||||
|
m_charWidthMaxAdj: 0
|
||||||
|
m_enableWordWrapping: 0
|
||||||
|
m_wordWrappingRatios: 0.4
|
||||||
|
m_overflowMode: 0
|
||||||
|
m_linkedTextComponent: {fileID: 0}
|
||||||
|
parentLinkedComponent: {fileID: 0}
|
||||||
|
m_enableKerning: 1
|
||||||
|
m_enableExtraPadding: 0
|
||||||
|
checkPaddingRequired: 0
|
||||||
|
m_isRichText: 1
|
||||||
|
m_parseCtrlCharacters: 1
|
||||||
|
m_isOrthographic: 1
|
||||||
|
m_isCullingEnabled: 0
|
||||||
|
m_horizontalMapping: 0
|
||||||
|
m_verticalMapping: 0
|
||||||
|
m_uvLineOffset: 0
|
||||||
|
m_geometrySortingOrder: 0
|
||||||
|
m_IsTextObjectScaleStatic: 0
|
||||||
|
m_VertexBufferAutoSizeReduction: 0
|
||||||
|
m_useMaxVisibleDescender: 1
|
||||||
|
m_pageToDisplay: 1
|
||||||
|
m_margin: {x: 0, y: 0, z: 0, w: 0}
|
||||||
|
m_isUsingLegacyAnimationComponent: 0
|
||||||
|
m_isVolumetricText: 0
|
||||||
|
m_hasFontAssetChanged: 0
|
||||||
|
m_baseMaterial: {fileID: 0}
|
||||||
|
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
|
||||||
--- !u!1 &1878107873570787823
|
--- !u!1 &1878107873570787823
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -124,11 +271,6 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 81a29b049c6380f4abb3c18ed121efcd, type: 3}
|
m_Script: {fileID: 11500000, guid: 81a29b049c6380f4abb3c18ed121efcd, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
minionTypes:
|
|
||||||
- {fileID: 0}
|
|
||||||
- {fileID: 0}
|
|
||||||
- {fileID: 0}
|
|
||||||
- {fileID: 0}
|
|
||||||
minionIconPrefab: {fileID: 1979632678310270257, guid: 2fee1ea5c97c5a04bb2c5f1f685fc92e, type: 3}
|
minionIconPrefab: {fileID: 1979632678310270257, guid: 2fee1ea5c97c5a04bb2c5f1f685fc92e, type: 3}
|
||||||
--- !u!114 &1878107873739935075
|
--- !u!114 &1878107873739935075
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
@ -188,6 +330,7 @@ RectTransform:
|
|||||||
m_Children:
|
m_Children:
|
||||||
- {fileID: 1878107874314509258}
|
- {fileID: 1878107874314509258}
|
||||||
- {fileID: 1878107873739935084}
|
- {fileID: 1878107873739935084}
|
||||||
|
- {fileID: 344214376}
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_RootOrder: 0
|
m_RootOrder: 0
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
|||||||
@ -134,6 +134,17 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 56c3e06ea5db48a40a7f55e72291cb0d, type: 3}
|
m_Script: {fileID: 11500000, guid: 56c3e06ea5db48a40a7f55e72291cb0d, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
--- !u!114 &344214379 stripped
|
||||||
|
MonoBehaviour:
|
||||||
|
m_CorrespondingSourceObject: {fileID: 344214379, guid: e1dac4f28fe75a547b919b7aa8240fed, type: 3}
|
||||||
|
m_PrefabInstance: {fileID: 1551362086}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: a53670f9cd399ea4a8ae3ed81b923aa8, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
--- !u!1001 &647315810
|
--- !u!1001 &647315810
|
||||||
PrefabInstance:
|
PrefabInstance:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -286,6 +297,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: e3fecdc4a8b2cb4419ef9d03180d130d, type: 3}
|
m_Script: {fileID: 11500000, guid: e3fecdc4a8b2cb4419ef9d03180d130d, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
gameTimer: {fileID: 344214379}
|
||||||
<Paused>k__BackingField: 1
|
<Paused>k__BackingField: 1
|
||||||
--- !u!114 &1464970062 stripped
|
--- !u!114 &1464970062 stripped
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
|
|||||||
@ -1,9 +1,12 @@
|
|||||||
|
using NaughtyAttributes;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.InputSystem;
|
using UnityEngine.InputSystem;
|
||||||
using UnityEngine.SceneManagement;
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
//Could be a singleton
|
//Could be a singleton
|
||||||
public class GameFlowManager : MonoBehaviour {
|
public class GameFlowManager : MonoBehaviour {
|
||||||
|
[SerializeField] [Required]
|
||||||
|
GameTimer gameTimer = null!;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// True if time is frozen (Start, Pause Menu, Dead)
|
/// True if time is frozen (Start, Pause Menu, Dead)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -80,8 +83,16 @@ public class GameFlowManager : MonoBehaviour {
|
|||||||
|
|
||||||
public override void EnterState() {
|
public override void EnterState() {
|
||||||
base.EnterState();
|
base.EnterState();
|
||||||
|
|
||||||
|
gameFlowManager.gameTimer.StartTimer();
|
||||||
gameFlowManager.SetPause(false);
|
gameFlowManager.SetPause(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void LeaveState() {
|
||||||
|
base.LeaveState();
|
||||||
|
|
||||||
|
gameFlowManager.gameTimer.PauseTimer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
class PauseMenuFlowState : GameFlowState {
|
class PauseMenuFlowState : GameFlowState {
|
||||||
public PauseMenuFlowState(GameFlowManager gameFlowManager) : base(gameFlowManager) {}
|
public PauseMenuFlowState(GameFlowManager gameFlowManager) : base(gameFlowManager) {}
|
||||||
|
|||||||
30
Assets/Scripts/GameTimer.cs
Normal file
30
Assets/Scripts/GameTimer.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class GameTimer : MonoBehaviour {
|
||||||
|
TMP_Text label;
|
||||||
|
float timer;
|
||||||
|
bool stopped;
|
||||||
|
|
||||||
|
void Awake() {
|
||||||
|
label = GetComponent<TMP_Text>();
|
||||||
|
stopped = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StartTimer() {
|
||||||
|
timer = Time.time;
|
||||||
|
stopped = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PauseTimer() => stopped = true;
|
||||||
|
|
||||||
|
void Update() {
|
||||||
|
if (stopped)
|
||||||
|
return;
|
||||||
|
|
||||||
|
timer += Time.deltaTime;
|
||||||
|
label.text = TimeSpan.FromSeconds(timer)
|
||||||
|
.ToString(@"mm\:ss");
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Scripts/GameTimer.cs.meta
Normal file
11
Assets/Scripts/GameTimer.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a53670f9cd399ea4a8ae3ed81b923aa8
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Loading…
x
Reference in New Issue
Block a user