From fa8cffae135bc7e9499d4599ff9ea99b50e6ea6a Mon Sep 17 00:00:00 2001 From: Philip White Date: Wed, 3 Nov 2021 00:05:42 +0000 Subject: [PATCH] Update ItemStash for Dissapearing Pasties --- .../Assets/Examples/Defender/Defender.unity | 4 ++-- .../Assets/Scripts/Gameplay/ItemStash.cs | 21 ++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Unity-Files/Assets/Examples/Defender/Defender.unity b/Unity-Files/Assets/Examples/Defender/Defender.unity index eb539d0..41b1eab 100644 --- a/Unity-Files/Assets/Examples/Defender/Defender.unity +++ b/Unity-Files/Assets/Examples/Defender/Defender.unity @@ -566,7 +566,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 353042924} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 4.28, y: 0.71000004, z: 0} + m_LocalPosition: {x: 7.18, y: 0.71000004, z: 0} m_LocalScale: {x: 1.5, y: 1.5, z: 0.5} m_Children: [] m_Father: {fileID: 965912684} @@ -1624,7 +1624,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1530896880} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -4.58, y: 0.71000004, z: 0} + m_LocalPosition: {x: -7.14, y: 0.71000004, z: 0} m_LocalScale: {x: 1.5, y: 1.5, z: 0.5} m_Children: [] m_Father: {fileID: 965912684} diff --git a/Unity-Files/Assets/Scripts/Gameplay/ItemStash.cs b/Unity-Files/Assets/Scripts/Gameplay/ItemStash.cs index 15edc46..86baed4 100644 --- a/Unity-Files/Assets/Scripts/Gameplay/ItemStash.cs +++ b/Unity-Files/Assets/Scripts/Gameplay/ItemStash.cs @@ -7,6 +7,8 @@ public class ItemStash : MonoBehaviour [Header("Dropped Item Amount")] public int droppedItemAmount = 3; + private GameObject[] pasties; + private void OnTriggerEnter2D(Collider2D other) { string objectTag = other.gameObject.tag; @@ -22,8 +24,25 @@ public class ItemStash : MonoBehaviour droppedItemAmount += 1; } + private void Start() + { + pasties = GameObject.FindGameObjectsWithTag("Pastie"); + } private void Update() { - + if (droppedItemAmount == 0 && pasties[0].GetComponent().enabled == true) + { + foreach (GameObject pastie in pasties) + { + pastie.GetComponent().enabled = false; + } + } + else if (droppedItemAmount != 0 && pasties[0].GetComponent().enabled == false) + { + foreach (GameObject pastie in pasties) + { + pastie.GetComponent().enabled = true; + } + } } }