diff --git a/Assets/BallonHandler.cs b/Assets/BallonHandler.cs index d760029..89b848c 100644 --- a/Assets/BallonHandler.cs +++ b/Assets/BallonHandler.cs @@ -21,7 +21,7 @@ void OnCollisionEnter(Collision col) { if(col.gameObject.name.Contains("Bolt")) { - bhandler.PopBallon(1); + bhandler.PopBallon(1, gameObject); gameObject.SetActive(false); ballonAudio.Play(0); } @@ -31,7 +31,7 @@ void OnTriggerEnter(Collider col) { if (col.gameObject.name.Contains("Bolt")) { - bhandler.PopBallon(1); + bhandler.PopBallon(1, gameObject); gameObject.SetActive(false); ballonAudio.Play(0); } diff --git a/Assets/BallonImageHandler.cs b/Assets/BallonImageHandler.cs index 8325b3c..8ac60f7 100644 --- a/Assets/BallonImageHandler.cs +++ b/Assets/BallonImageHandler.cs @@ -12,6 +12,7 @@ public class BallonImageHandler : MonoBehaviour { public Text console; public TextMeshPro front; public TextMeshPro back; + public List ballons; private const int level1BallonsTotal = 10; @@ -22,7 +23,7 @@ public class BallonImageHandler : MonoBehaviour { // Use this for initialization void Start () { - + ballons = new List(); } // Update is called once per frame @@ -50,9 +51,10 @@ void Update () } } - public void PopBallon(int level) + public void PopBallon(int level, GameObject ballon) { level1Ballons++; + ballons.Add(ballon); if(level == 1 && level1Ballons == 1) { @@ -83,10 +85,26 @@ void ResetGame() child.gameObject.SetActive(true); } + ballons = new List(); gameStarted = false; gameTime = 0.0F; level1Ballons = 0; + } + public void Undo() + { + if(gameStarted) + { + int index = ballons.Count; + + if(index > 0) + { + ballons[index - 1].SetActive(true); + ballons.Remove(ballons[index - 1]); + level1Ballons--; + } + } + } } diff --git a/Assets/Scenes/MainScene.unity b/Assets/Scenes/MainScene.unity index ee13727..ec082b8 100644 --- a/Assets/Scenes/MainScene.unity +++ b/Assets/Scenes/MainScene.unity @@ -9627,6 +9627,7 @@ GameObject: - component: {fileID: 1159778320} - component: {fileID: 1159778319} - component: {fileID: 1159778318} + - component: {fileID: 1159778321} m_Layer: 5 m_Name: UndoButton m_TagString: Untagged @@ -9728,6 +9729,19 @@ CanvasRenderer: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 1159778316} m_CullTransparentMesh: 0 +--- !u!114 &1159778321 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1159778316} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f39ae345006ac34439a9940db524a9c9, type: 3} + m_Name: + m_EditorClassIdentifier: + btn: {fileID: 1159778318} + handler: {fileID: 2108964572} --- !u!1 &1165980183 GameObject: m_ObjectHideFlags: 0 @@ -16872,6 +16886,12 @@ MeshFilter: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 2087131127} m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!114 &2108964572 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 114816571305489748, guid: e0aba74480574f74bb472bbb64f825e7, + type: 2} + m_PrefabInternal: {fileID: 797608226} + m_Script: {fileID: 11500000, guid: 341fd65ce12642e4ca2eaff0dfb9c910, type: 3} --- !u!1 &2117357759 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/UndoButtonHandler.cs b/Assets/UndoButtonHandler.cs new file mode 100644 index 0000000..1ff005e --- /dev/null +++ b/Assets/UndoButtonHandler.cs @@ -0,0 +1,25 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine.UI; +using UnityEngine; + +public class UndoButtonHandler : MonoBehaviour { + + public Button btn; + public BallonImageHandler handler; + + // Use this for initialization + void Start () { + btn.onClick.AddListener(OnClick); + } + + // Update is called once per frame + void Update () { + + } + + void OnClick() + { + handler.Undo(); + } +} diff --git a/Assets/UndoButtonHandler.cs.meta b/Assets/UndoButtonHandler.cs.meta new file mode 100644 index 0000000..5037799 --- /dev/null +++ b/Assets/UndoButtonHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f39ae345006ac34439a9940db524a9c9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: