Added bot for start screen and Apple Picker text
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class AppleTree : MonoBehaviour
|
||||
{
|
||||
@@ -23,6 +24,7 @@ public class AppleTree : MonoBehaviour
|
||||
{
|
||||
// Dropping apples every second
|
||||
Invoke("DropApple", 2f);
|
||||
if (SceneManager.GetActiveScene().name == "_Scene_2") { return; }
|
||||
// Dropping rotten apples every 3 seconds
|
||||
Invoke("DropRottenApple", 2f);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ public class Basket : MonoBehaviour
|
||||
{
|
||||
[Header("Set Dynamically")]
|
||||
public Text scoreGT;
|
||||
float botSpeed = 15f;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
@@ -23,7 +24,11 @@ public class Basket : MonoBehaviour
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (SceneManager.GetActiveScene().name == "_Scene_2") { return; }
|
||||
if (SceneManager.GetActiveScene().name == "_Scene_2") { GetBotInput(); }
|
||||
else { GetPlayerInput(); }
|
||||
}
|
||||
|
||||
void GetPlayerInput() {
|
||||
// Get the current screen position of the mouse from Input
|
||||
Vector3 mousePos2D = Input.mousePosition;
|
||||
// The Camera's z position sets how far to push the mouse into 3D
|
||||
@@ -36,6 +41,23 @@ public class Basket : MonoBehaviour
|
||||
this.transform.position = pos;
|
||||
}
|
||||
|
||||
void GetBotInput() {
|
||||
float basketHeight = this.transform.position.y;
|
||||
float currentMin = 999;
|
||||
float directionToGo = this.transform.position.x;
|
||||
GameObject[] tAppleArray = GameObject.FindGameObjectsWithTag("Apple");
|
||||
foreach (GameObject tGO in tAppleArray) {
|
||||
if (tGO.transform.position.y - basketHeight < currentMin) {
|
||||
currentMin = tGO.transform.position.y - basketHeight;
|
||||
if (tGO.transform.position.x > this.transform.position.x) { directionToGo = 1; }
|
||||
else { directionToGo = -1; }
|
||||
}
|
||||
}
|
||||
Vector3 pos = transform.position;
|
||||
pos.x += botSpeed * Time.deltaTime * directionToGo;
|
||||
transform.position = pos;
|
||||
}
|
||||
|
||||
void OnCollisionEnter(Collision coll) {
|
||||
// Find out what hit this basket
|
||||
GameObject collidedWith = coll.gameObject;
|
||||
|
||||
Reference in New Issue
Block a user