Added reset button. Resets on normal apples for some reason

This commit is contained in:
Trianta
2024-02-08 18:42:57 -06:00
parent 22c4d22165
commit 70ef029ae4
5 changed files with 279 additions and 21 deletions
+2 -3
View File
@@ -2,7 +2,6 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class ApplePicker : MonoBehaviour
{
@@ -14,6 +13,7 @@ public class ApplePicker : MonoBehaviour
public List<GameObject> basketList;
public Text roundGT;
public Button resetButton;
// Start is called before the first frame update
void Start()
@@ -66,8 +66,7 @@ public class ApplePicker : MonoBehaviour
public void GameOver() {
Time.timeScale = 0;
roundGT.text = "Game Over";
SceneManager.LoadScene("_Scene_0");
Time.timeScale = 1;
resetButton.gameObject.SetActive(true);
}
// Update is called once per frame
+19 -17
View File
@@ -36,23 +36,25 @@ public class Basket : MonoBehaviour
void OnCollisionEnter(Collision coll) {
// Find out what hit this basket
GameObject collidedWith = coll.gameObject;
if (collidedWith.tag == "Apple") {
Destroy(collidedWith);
// Parse the text of the scoreGT into an int
int score = int.Parse(scoreGT.text);
// Add points for catching the apple
score += 100;
// Convert the score back to a string and display it
scoreGT.text = score.ToString();
// Track the high score
if (score > HighScore.score) {
HighScore.score = score;
}
}
if (collidedWith.tag == "RottenApple") {
Destroy(collidedWith);
ApplePicker apScript = Camera.main.GetComponent<ApplePicker>();
apScript.RottenAppleDestroyed();
switch (collidedWith.tag) {
case "Apple":
Destroy(collidedWith);
// Parse the text of the scoreGT into an int
int score = int.Parse(scoreGT.text);
// Add points for catching the apple
score += 100;
// Convert the score back to a string and display it
scoreGT.text = score.ToString();
// Track the high score
if (score > HighScore.score) { HighScore.score = score; }
break;
case "RottenApple":
Destroy(collidedWith);
ApplePicker apScript = Camera.main.GetComponent<ApplePicker>();
apScript.RottenAppleDestroyed();
break;
default:
break;
}
}
}
+28
View File
@@ -0,0 +1,28 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Reset : MonoBehaviour
{
public Button m_ResetButton;
// Start is called before the first frame update
void Start()
{
m_ResetButton.onClick.AddListener(() => ButtonClicked());
this.gameObject.SetActive(false);
}
void ButtonClicked() {
SceneManager.LoadScene("_Scene_0");
Time.timeScale = 1;
this.gameObject.SetActive(false);
}
// Update is called once per frame
void Update()
{
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 894fa7fb2c53ceb4d89a510c57b98e61
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: