Skip to content
This repository has been archived by the owner on Mar 17, 2020. It is now read-only.

Commit

Permalink
undo button
Browse files Browse the repository at this point in the history
  • Loading branch information
excelsi0r committed Nov 6, 2018
1 parent b243f75 commit 948b0fb
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Assets/BallonHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
22 changes: 20 additions & 2 deletions Assets/BallonImageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class BallonImageHandler : MonoBehaviour {
public Text console;
public TextMeshPro front;
public TextMeshPro back;
public List<GameObject> ballons;

private const int level1BallonsTotal = 10;

Expand All @@ -22,7 +23,7 @@ public class BallonImageHandler : MonoBehaviour {

// Use this for initialization
void Start () {
ballons = new List<GameObject>();
}

// Update is called once per frame
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -83,10 +85,26 @@ void ResetGame()
child.gameObject.SetActive(true);
}

ballons = new List<GameObject>();
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--;
}
}
}

}
20 changes: 20 additions & 0 deletions Assets/Scenes/MainScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions Assets/UndoButtonHandler.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
11 changes: 11 additions & 0 deletions Assets/UndoButtonHandler.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 948b0fb

Please sign in to comment.