Added RottenApples that GameOver if caught

This commit is contained in:
Trianta
2024-02-08 17:27:45 -06:00
parent b9fced5e18
commit 22c4d22165
12 changed files with 298 additions and 4 deletions
+17 -2
View File
@@ -50,11 +50,26 @@ public class ApplePicker : MonoBehaviour
roundGT.text += numBaskets - basketList.Count + 1;
// If there are no Baskets left, restart the game
if (basketList.Count == 0) {
roundGT.text = "Game Over";
SceneManager.LoadScene("_Scene_0");
GameOver();
}
}
public void RottenAppleDestroyed() {
// Destroy all of the falling apples
GameObject[] tAppleArray = GameObject.FindGameObjectsWithTag("Apple");
foreach (GameObject tGO in tAppleArray) {
Destroy(tGO);
}
GameOver();
}
public void GameOver() {
Time.timeScale = 0;
roundGT.text = "Game Over";
SceneManager.LoadScene("_Scene_0");
Time.timeScale = 1;
}
// Update is called once per frame
void Update()
{
+11
View File
@@ -7,6 +7,7 @@ public class AppleTree : MonoBehaviour
[Header("Set in Inspector")]
// Prefab for instantiating apples
public GameObject applePrefab;
public GameObject rottenApplePrefab;
// Speed at which the AppleTree moves
public float speed = 1f;
// Distance where AppleTree turns around
@@ -15,11 +16,15 @@ public class AppleTree : MonoBehaviour
public float chanceToChangeDirections = 0.1f;
// Rate at which Apples will be instantiated
public float secondsBetweenAppleDrops = 1f;
// Rate at which RottenApples will be instantiated
public float secondsBetweenRottenAppleDrops = 3f;
// Start is called before the first frame update
void Start()
{
// Dropping apples every second
Invoke("DropApple", 2f);
// Dropping rotten apples every 3 seconds
Invoke("DropRottenApple", 2f);
}
void DropApple() {
@@ -28,6 +33,12 @@ public class AppleTree : MonoBehaviour
Invoke("DropApple", secondsBetweenAppleDrops);
}
void DropRottenApple() {
GameObject rottenApple = Instantiate<GameObject>(rottenApplePrefab);
rottenApple.transform.position = transform.position;
Invoke("DropRottenApple", secondsBetweenRottenAppleDrops);
}
// Update is called once per frame
void Update()
{
+5
View File
@@ -49,5 +49,10 @@ public class Basket : MonoBehaviour
HighScore.score = score;
}
}
if (collidedWith.tag == "RottenApple") {
Destroy(collidedWith);
ApplePicker apScript = Camera.main.GetComponent<ApplePicker>();
apScript.RottenAppleDestroyed();
}
}
}
+22
View File
@@ -0,0 +1,22 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RottenApple : MonoBehaviour
{
[Header("Set in Inspector")]
public static float bottomY = -20f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (transform.position.y < bottomY) {
Destroy(this.gameObject);
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a833b002908db9212a4486fe67e0969a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: