Fixed apples spawning on top of each other
This commit is contained in:
@@ -65,6 +65,11 @@ public class ApplePicker : MonoBehaviour
|
||||
GameOver();
|
||||
}
|
||||
|
||||
public void GoldenAppleDestroyed() {
|
||||
AppleTree appleTree = GameObject.FindGameObjectWithTag("AppleTree").GetComponent<AppleTree>();
|
||||
appleTree.GoldenAppleTimeStart();
|
||||
}
|
||||
|
||||
public void GameOver() {
|
||||
Time.timeScale = 0;
|
||||
roundGT.text = "Game Over";
|
||||
|
||||
@@ -9,6 +9,7 @@ public class AppleTree : MonoBehaviour
|
||||
// Prefab for instantiating apples
|
||||
public GameObject applePrefab;
|
||||
public GameObject rottenApplePrefab;
|
||||
public GameObject goldenApplePrefab;
|
||||
// Speed at which the AppleTree moves
|
||||
public float speed = 1f;
|
||||
// Distance where AppleTree turns around
|
||||
@@ -18,15 +19,21 @@ public class AppleTree : MonoBehaviour
|
||||
// Rate at which Apples will be instantiated
|
||||
public float secondsBetweenAppleDrops = 1f;
|
||||
// Rate at which RottenApples will be instantiated
|
||||
public float secondsBetweenRottenAppleDrops = 3f;
|
||||
public float secondsBetweenRottenAppleDrops = 2f;
|
||||
// Rate at which RottenApples will be instantiated
|
||||
public float secondsBetweenGoldenAppleDrops = 4f;
|
||||
public bool goldenAppleTime = false;
|
||||
public float goldenAppleTimeCurrent = 0f;
|
||||
public float goldenAppleTimeLimit = 5f;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
// Dropping apples every second
|
||||
Invoke("DropApple", 2f);
|
||||
Invoke("DropApple", 1f);
|
||||
if (SceneManager.GetActiveScene().name == "_Scene_2") { return; }
|
||||
// Dropping rotten apples every 3 seconds
|
||||
Invoke("DropRottenApple", 2f);
|
||||
Invoke("DropGoldenApple", 4f);
|
||||
}
|
||||
|
||||
void DropApple() {
|
||||
@@ -41,6 +48,29 @@ public class AppleTree : MonoBehaviour
|
||||
Invoke("DropRottenApple", secondsBetweenRottenAppleDrops);
|
||||
}
|
||||
|
||||
void DropGoldenApple() {
|
||||
GameObject goldenApple = Instantiate<GameObject>(goldenApplePrefab);
|
||||
goldenApple.transform.position = transform.position;
|
||||
if (goldenAppleTime) {
|
||||
Invoke("DropGoldenApple", secondsBetweenGoldenAppleDrops + goldenAppleTimeLimit);
|
||||
} else {
|
||||
Invoke("DropGoldenApple", secondsBetweenGoldenAppleDrops);
|
||||
}
|
||||
}
|
||||
|
||||
public void GoldenAppleTimeStart() {
|
||||
AppleTree atScript = Camera.main.GetComponent<AppleTree>();
|
||||
atScript.goldenAppleTime = true;
|
||||
atScript.secondsBetweenAppleDrops *= 0.25f;
|
||||
}
|
||||
|
||||
public void GoldenAppleTimeEnd() {
|
||||
AppleTree atScript = Camera.main.GetComponent<AppleTree>();
|
||||
atScript.goldenAppleTime = false;
|
||||
goldenAppleTimeCurrent = 0f;
|
||||
atScript.secondsBetweenAppleDrops *= 4;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
@@ -54,6 +84,13 @@ public class AppleTree : MonoBehaviour
|
||||
} else if (pos.x > leftAndRightEdge) {
|
||||
speed = -Mathf.Abs(speed);
|
||||
}
|
||||
|
||||
if (goldenAppleTime) {
|
||||
goldenAppleTimeCurrent += Time.deltaTime;
|
||||
if (goldenAppleTimeCurrent > goldenAppleTimeLimit) {
|
||||
GoldenAppleTimeEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update exactly 50 times per second
|
||||
|
||||
@@ -61,7 +61,17 @@ public class Basket : MonoBehaviour
|
||||
void OnCollisionEnter(Collision coll) {
|
||||
// Find out what hit this basket
|
||||
GameObject collidedWith = coll.gameObject;
|
||||
ApplePicker apScript = Camera.main.GetComponent<ApplePicker>();
|
||||
switch (collidedWith.tag) {
|
||||
case "RottenApple":
|
||||
Destroy(collidedWith);
|
||||
if (SceneManager.GetActiveScene().name == "_Scene_2") { return; }
|
||||
apScript.RottenAppleDestroyed();
|
||||
break;
|
||||
case "GoldenApple":
|
||||
Destroy(collidedWith);
|
||||
apScript.GoldenAppleDestroyed();
|
||||
break;
|
||||
case "Apple":
|
||||
Destroy(collidedWith);
|
||||
if (SceneManager.GetActiveScene().name == "_Scene_2") { return; }
|
||||
@@ -74,12 +84,6 @@ public class Basket : MonoBehaviour
|
||||
// Track the high score
|
||||
if (score > HighScore.score) { HighScore.score = score; }
|
||||
break;
|
||||
case "RottenApple":
|
||||
Destroy(collidedWith);
|
||||
if (SceneManager.GetActiveScene().name == "_Scene_2") { return; }
|
||||
ApplePicker apScript = Camera.main.GetComponent<ApplePicker>();
|
||||
apScript.RottenAppleDestroyed();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class GoldenApple : MonoBehaviour
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 735ca23f10b0eb1b4b902456bc9536b3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user