From b436c41b0f20ffa961956a60933f8df83c22a164 Mon Sep 17 00:00:00 2001 From: Trianta <56975502+Trimutex@users.noreply.github.com> Date: Thu, 8 Feb 2024 19:38:37 -0600 Subject: [PATCH] Added bot for start screen and Apple Picker text --- Assets/Scenes/_Scene_2.unity | 87 ++++++++++++++++++++++++++++++++++-- Assets/Scripts/AppleTree.cs | 2 + Assets/Scripts/Basket.cs | 24 +++++++++- 3 files changed, 109 insertions(+), 4 deletions(-) diff --git a/Assets/Scenes/_Scene_2.unity b/Assets/Scenes/_Scene_2.unity index 3667f04..2de6948 100644 --- a/Assets/Scenes/_Scene_2.unity +++ b/Assets/Scenes/_Scene_2.unity @@ -191,6 +191,86 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &333221063 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 333221064} + - component: {fileID: 333221066} + - component: {fileID: 333221065} + m_Layer: 5 + m_Name: Text (Legacy) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &333221064 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 333221063} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 1391927209} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: 83.5} + m_SizeDelta: {x: -800, y: -527} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &333221065 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 333221063} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 0.6509434, g: 0.15659486, b: 0.15659486, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_FontData: + m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} + m_FontSize: 48 + m_FontStyle: 1 + m_BestFit: 0 + m_MinSize: 3 + m_MaxSize: 48 + m_Alignment: 4 + m_AlignByGeometry: 0 + m_RichText: 1 + m_HorizontalOverflow: 0 + m_VerticalOverflow: 0 + m_LineSpacing: 1 + m_Text: Apple Picker +--- !u!222 &333221066 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 333221063} + m_CullTransparentMesh: 1 --- !u!1 &705507993 GameObject: m_ObjectHideFlags: 0 @@ -345,10 +425,10 @@ MonoBehaviour: m_Calls: [] m_FontData: m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} - m_FontSize: 14 - m_FontStyle: 0 + m_FontSize: 16 + m_FontStyle: 1 m_BestFit: 0 - m_MinSize: 10 + m_MinSize: 1 m_MaxSize: 40 m_Alignment: 4 m_AlignByGeometry: 0 @@ -562,6 +642,7 @@ RectTransform: m_ConstrainProportionsScale: 0 m_Children: - {fileID: 1394167064} + - {fileID: 333221064} m_Father: {fileID: 0} m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/Scripts/AppleTree.cs b/Assets/Scripts/AppleTree.cs index a34a893..58b652d 100644 --- a/Assets/Scripts/AppleTree.cs +++ b/Assets/Scripts/AppleTree.cs @@ -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); } diff --git a/Assets/Scripts/Basket.cs b/Assets/Scripts/Basket.cs index 9f53768..96ba0b0 100644 --- a/Assets/Scripts/Basket.cs +++ b/Assets/Scripts/Basket.cs @@ -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;