From d9ec87813294ec266cef922c9e05534e33173a61 Mon Sep 17 00:00:00 2001 From: Trianta <56975502+Trimutex@users.noreply.github.com> Date: Thu, 8 Feb 2024 21:10:54 -0600 Subject: [PATCH] Fixed apples spawning on top of each other --- Assets/Materials/Mat_GoldenApple.mat | 80 ++++++++++++++ Assets/Materials/Mat_GoldenApple.mat.meta | 8 ++ Assets/Prefabs/GoldenApple.prefab | 129 ++++++++++++++++++++++ Assets/Prefabs/GoldenApple.prefab.meta | 7 ++ Assets/Prefabs/RottenApple.prefab.meta | 2 +- Assets/Scenes/_Scene_0.unity | 10 +- Assets/Scripts/ApplePicker.cs | 5 + Assets/Scripts/AppleTree.cs | 41 ++++++- Assets/Scripts/Basket.cs | 16 ++- Assets/Scripts/GoldenApple.cs | 22 ++++ Assets/Scripts/GoldenApple.cs.meta | 11 ++ ProjectSettings/DynamicsManager.asset | 2 +- ProjectSettings/TagManager.asset | 5 +- 13 files changed, 325 insertions(+), 13 deletions(-) create mode 100644 Assets/Materials/Mat_GoldenApple.mat create mode 100644 Assets/Materials/Mat_GoldenApple.mat.meta create mode 100644 Assets/Prefabs/GoldenApple.prefab create mode 100644 Assets/Prefabs/GoldenApple.prefab.meta create mode 100644 Assets/Scripts/GoldenApple.cs create mode 100644 Assets/Scripts/GoldenApple.cs.meta diff --git a/Assets/Materials/Mat_GoldenApple.mat b/Assets/Materials/Mat_GoldenApple.mat new file mode 100644 index 0000000..83f7a9a --- /dev/null +++ b/Assets/Materials/Mat_GoldenApple.mat @@ -0,0 +1,80 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: Mat_GoldenApple + m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} + m_ValidKeywords: [] + m_InvalidKeywords: [] + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] + m_Floats: + - _BumpScale: 1 + - _Cutoff: 0.5 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _GlossMapScale: 1 + - _Glossiness: 0.5 + - _GlossyReflections: 1 + - _Metallic: 0 + - _Mode: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.02 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _UVSec: 0 + - _ZWrite: 1 + m_Colors: + - _Color: {r: 0.8015952, g: 0.8490566, b: 0.020024916, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + m_BuildTextureStacks: [] diff --git a/Assets/Materials/Mat_GoldenApple.mat.meta b/Assets/Materials/Mat_GoldenApple.mat.meta new file mode 100644 index 0000000..d087282 --- /dev/null +++ b/Assets/Materials/Mat_GoldenApple.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 55548ebb6b250a39ba3c37a846f83224 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/GoldenApple.prefab b/Assets/Prefabs/GoldenApple.prefab new file mode 100644 index 0000000..93aefb0 --- /dev/null +++ b/Assets/Prefabs/GoldenApple.prefab @@ -0,0 +1,129 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &1428767985013339637 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1428767985013339632} + - component: {fileID: 1428767985013339633} + - component: {fileID: 1428767985013339634} + - component: {fileID: 1428767985013339635} + - component: {fileID: 1428767985013339636} + - component: {fileID: -2558008178231210607} + m_Layer: 12 + m_Name: GoldenApple + m_TagString: GoldenApple + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1428767985013339632 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1428767985013339637} + 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: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!33 &1428767985013339633 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1428767985013339637} + m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} +--- !u!23 &1428767985013339634 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1428767985013339637} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 55548ebb6b250a39ba3c37a846f83224, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_AdditionalVertexStreams: {fileID: 0} +--- !u!135 &1428767985013339635 +SphereCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1428767985013339637} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Radius: 0.5 + m_Center: {x: 0, y: 0, z: 0} +--- !u!54 &1428767985013339636 +Rigidbody: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1428767985013339637} + serializedVersion: 2 + m_Mass: 1 + m_Drag: 0 + m_AngularDrag: 0.05 + m_UseGravity: 1 + m_IsKinematic: 0 + m_Interpolate: 0 + m_Constraints: 0 + m_CollisionDetection: 0 +--- !u!114 &-2558008178231210607 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1428767985013339637} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 735ca23f10b0eb1b4b902456bc9536b3, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/Assets/Prefabs/GoldenApple.prefab.meta b/Assets/Prefabs/GoldenApple.prefab.meta new file mode 100644 index 0000000..5c472d2 --- /dev/null +++ b/Assets/Prefabs/GoldenApple.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: db7d7f53e4b04e16596115dbcc4f31c1 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/RottenApple.prefab.meta b/Assets/Prefabs/RottenApple.prefab.meta index 5c472d2..b57c048 100644 --- a/Assets/Prefabs/RottenApple.prefab.meta +++ b/Assets/Prefabs/RottenApple.prefab.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: db7d7f53e4b04e16596115dbcc4f31c1 +guid: 5a3f43c14ed51073380e9516bd98d47c PrefabImporter: externalObjects: {} userData: diff --git a/Assets/Scenes/_Scene_0.unity b/Assets/Scenes/_Scene_0.unity index c44fd0c..ed36625 100644 --- a/Assets/Scenes/_Scene_0.unity +++ b/Assets/Scenes/_Scene_0.unity @@ -977,6 +977,10 @@ PrefabInstance: propertyPath: m_Name value: AppleTree objectReference: {fileID: 0} + - target: {fileID: 2963219029695693475, guid: 7f43e61e14d39c9608ac9a44321a0dc8, type: 3} + propertyPath: m_TagString + value: AppleTree + objectReference: {fileID: 0} - target: {fileID: 2963219029695693477, guid: 7f43e61e14d39c9608ac9a44321a0dc8, type: 3} propertyPath: m_RootOrder value: 2 @@ -1034,9 +1038,13 @@ PrefabInstance: value: 20 objectReference: {fileID: 0} - target: {fileID: 8871816599865554133, guid: 7f43e61e14d39c9608ac9a44321a0dc8, type: 3} - propertyPath: rottenApplePrefab + propertyPath: goldenApplePrefab value: objectReference: {fileID: 1428767985013339637, guid: db7d7f53e4b04e16596115dbcc4f31c1, type: 3} + - target: {fileID: 8871816599865554133, guid: 7f43e61e14d39c9608ac9a44321a0dc8, type: 3} + propertyPath: rottenApplePrefab + value: + objectReference: {fileID: 1428767985013339637, guid: 5a3f43c14ed51073380e9516bd98d47c, type: 3} - target: {fileID: 8871816599865554133, guid: 7f43e61e14d39c9608ac9a44321a0dc8, type: 3} propertyPath: chanceToChangeDirections value: 0.02 diff --git a/Assets/Scripts/ApplePicker.cs b/Assets/Scripts/ApplePicker.cs index aaa48c9..27f889f 100644 --- a/Assets/Scripts/ApplePicker.cs +++ b/Assets/Scripts/ApplePicker.cs @@ -65,6 +65,11 @@ public class ApplePicker : MonoBehaviour GameOver(); } + public void GoldenAppleDestroyed() { + AppleTree appleTree = GameObject.FindGameObjectWithTag("AppleTree").GetComponent(); + appleTree.GoldenAppleTimeStart(); + } + public void GameOver() { Time.timeScale = 0; roundGT.text = "Game Over"; diff --git a/Assets/Scripts/AppleTree.cs b/Assets/Scripts/AppleTree.cs index 58b652d..995f131 100644 --- a/Assets/Scripts/AppleTree.cs +++ b/Assets/Scripts/AppleTree.cs @@ -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(goldenApplePrefab); + goldenApple.transform.position = transform.position; + if (goldenAppleTime) { + Invoke("DropGoldenApple", secondsBetweenGoldenAppleDrops + goldenAppleTimeLimit); + } else { + Invoke("DropGoldenApple", secondsBetweenGoldenAppleDrops); + } + } + + public void GoldenAppleTimeStart() { + AppleTree atScript = Camera.main.GetComponent(); + atScript.goldenAppleTime = true; + atScript.secondsBetweenAppleDrops *= 0.25f; + } + + public void GoldenAppleTimeEnd() { + AppleTree atScript = Camera.main.GetComponent(); + 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 diff --git a/Assets/Scripts/Basket.cs b/Assets/Scripts/Basket.cs index 96ba0b0..047b4f9 100644 --- a/Assets/Scripts/Basket.cs +++ b/Assets/Scripts/Basket.cs @@ -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(); 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(); - apScript.RottenAppleDestroyed(); - break; default: break; } diff --git a/Assets/Scripts/GoldenApple.cs b/Assets/Scripts/GoldenApple.cs new file mode 100644 index 0000000..86d4af2 --- /dev/null +++ b/Assets/Scripts/GoldenApple.cs @@ -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); + } + + } +} diff --git a/Assets/Scripts/GoldenApple.cs.meta b/Assets/Scripts/GoldenApple.cs.meta new file mode 100644 index 0000000..d7c8a14 --- /dev/null +++ b/Assets/Scripts/GoldenApple.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 735ca23f10b0eb1b4b902456bc9536b3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectSettings/DynamicsManager.asset b/ProjectSettings/DynamicsManager.asset index 85279e9..3118fcb 100644 --- a/ProjectSettings/DynamicsManager.asset +++ b/ProjectSettings/DynamicsManager.asset @@ -18,7 +18,7 @@ PhysicsManager: m_ClothInterCollisionDistance: 0 m_ClothInterCollisionStiffness: 0 m_ContactsGeneration: 1 - m_LayerCollisionMatrix: fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdfffffffcffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff + m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe5ffffffe4ffffffffffffffe4ffffffe4ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff m_AutoSimulation: 1 m_AutoSyncTransforms: 0 m_ReuseCollisionCallbacks: 1 diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index 8e70c76..943449d 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -6,7 +6,8 @@ TagManager: tags: - Apple - RottenApple - - Undefined + - GoldenApple + - AppleTree layers: - Default - TransparentFX @@ -20,7 +21,7 @@ TagManager: - Apple - Basket - RottenApple - - + - GoldenApple - - -