Back button: Implement reactions on Scenes

parent 929d90b5
...@@ -4,6 +4,7 @@ using System.Collections; ...@@ -4,6 +4,7 @@ using System.Collections;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using Assets.Scripts; using Assets.Scripts;
using Assets.Scripts.API; using Assets.Scripts.API;
using Assets.Scripts.Utils;
public class GameOver : MonoBehaviour public class GameOver : MonoBehaviour
{ {
...@@ -28,6 +29,7 @@ public class GameOver : MonoBehaviour ...@@ -28,6 +29,7 @@ public class GameOver : MonoBehaviour
// SceneManager.LoadScene("Menu"); // SceneManager.LoadScene("Menu");
score = PlayerPrefs.GetInt("lastscore"); score = PlayerPrefs.GetInt("lastscore");
Score.text = "You scored " + score; Score.text = "You scored " + score;
BackButtonHelper.playOnBack();
} }
public void OnButtonPlayClicked() public void OnButtonPlayClicked()
......
using Assets.Scripts.API; using Assets.Scripts.API;
using Assets.Scripts.Utils;
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using UnityEngine.UI; using UnityEngine.UI;
...@@ -21,6 +22,7 @@ public class HighScores : MonoBehaviour { ...@@ -21,6 +22,7 @@ public class HighScores : MonoBehaviour {
// Update is called once per frame // Update is called once per frame
void Update () { void Update () {
BackButtonHelper.playOnBack();
if (!updatedScores) { if (!updatedScores) {
if (Server.Scores.status.Equals("ok")) { if (Server.Scores.status.Equals("ok")) {
Score[] highScores = Server.Scores.scores; Score[] highScores = Server.Scores.scores;
......
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using Assets.Scripts.Utils;
public class Menu : MonoBehaviour { public class Menu : MonoBehaviour {
...@@ -11,7 +12,7 @@ public class Menu : MonoBehaviour { ...@@ -11,7 +12,7 @@ public class Menu : MonoBehaviour {
// Update is called once per frame // Update is called once per frame
void Update () { void Update () {
BackButtonHelper.quitOnBack();
} }
public void OnButtonPlayClicked() public void OnButtonPlayClicked()
......
...@@ -3,6 +3,7 @@ using UnityEngine; ...@@ -3,6 +3,7 @@ using UnityEngine;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using Assets.Scripts; using Assets.Scripts;
using Assets.Scripts.Utils;
using UnityEngine.UI; using UnityEngine.UI;
public class UIController : MonoBehaviour public class UIController : MonoBehaviour
...@@ -37,6 +38,7 @@ public class UIController : MonoBehaviour ...@@ -37,6 +38,7 @@ public class UIController : MonoBehaviour
DisplayBattery(); DisplayBattery();
HandlePowerUps(); HandlePowerUps();
HandleScore(); HandleScore();
BackButtonHelper.menuOnBack();
} }
private void HandleScore() private void HandleScore()
......
using System;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace Assets.Scripts.Utils
{
public static class BackButtonHelper
{
public static void quitOnBack() {
if (Input.GetKeyDown(KeyCode.Escape))
Application.Quit();
}
public static void menuOnBack() {
if (Input.GetKeyDown(KeyCode.Escape))
SceneManager.LoadScene("Menu");
}
public static void playOnBack() {
if (Input.GetKeyDown(KeyCode.Escape))
SceneManager.LoadScene("Main");
}
}
}
fileFormatVersion: 2
guid: 3be153ffde4554d9cbb676f03dc3005d
timeCreated: 1477660884
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment