From d352ad391f6309ba4b1005646dd8da83a02d8332 Mon Sep 17 00:00:00 2001 From: alilas2 Date: Sun, 12 Jun 2022 17:18:43 +0200 Subject: [PATCH] Improved possible action panel --- Assets/OpenPanelOnCollision.cs | 75 +++++++++++++++++++++-- Assets/Scenes/SampleScene.unity | 12 ++++ Assets/Scripts/Item/PickableController.cs | 2 +- Assets/Scripts/QuitGame.cs | 2 +- Assets/breakable.cs | 4 +- UserSettings/EditorUserSettings.asset | 6 +- 6 files changed, 90 insertions(+), 11 deletions(-) diff --git a/Assets/OpenPanelOnCollision.cs b/Assets/OpenPanelOnCollision.cs index 3fb94825..8ae8fc3f 100644 --- a/Assets/OpenPanelOnCollision.cs +++ b/Assets/OpenPanelOnCollision.cs @@ -10,10 +10,15 @@ public class OpenPanelOnCollision : MonoBehaviour public GameObject SecondPanel; public GameObject PanelAbove; + public GameObject obj; + + private bool inRange = false; + private void OnTriggerEnter2D(Collider2D collision) { if(collision.tag == "Player") { + inRange = true; if(SecondPanel.active == false) { Panel.SetActive(true); @@ -25,16 +30,77 @@ public class OpenPanelOnCollision : MonoBehaviour } } - void Update() + private void OnTriggerStay2D(Collider2D collision) { - if(OtherPanel.active == true) + if (collision.tag == "Player") + { + inRange = true; + if(OtherPanel.active == true) + { + if (SecondPanel.active == false) + { + Panel.SetActive(false); + } + else + { + SecondPanel.SetActive(false); + PanelAbove.SetActive(false); + } + } + else if (SecondPanel.active == false) + { + Panel.SetActive(true); + } + else + { + PanelAbove.SetActive(true); + } + } + } + + + IEnumerator Timer1() + { + yield return new WaitForSeconds(0.3f); + if(inRange == false) { Panel.SetActive(false); } + } + + IEnumerator Timer2() + { + yield return new WaitForSeconds(0.3f); + if (inRange == false) + { + PanelAbove.SetActive(false); + } + } + + void Update() + { + + if(obj.active == false) + { + if (Panel.active == true) + { + Panel.SetActive(false); + } + else if (PanelAbove.active == true) + { + PanelAbove.SetActive(false); + } + } + + if(OtherPanel.active == true) + { + StartCoroutine(Timer1()); + } if(SecondPanel.active == false) { if(PanelAbove.active == true) { + StartCoroutine(Timer2()); PanelAbove.SetActive(false); Panel.SetActive(true); } @@ -43,13 +109,14 @@ public class OpenPanelOnCollision : MonoBehaviour private void OnTriggerExit2D(Collider2D collision) { + inRange = false; if(Panel.active == true) { - Panel.SetActive(false); + StartCoroutine(Timer1()); } else if(PanelAbove.active == true) { - PanelAbove.SetActive(false); + StartCoroutine(Timer2()); } } } diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 7cbdc4c6..0303a2f2 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -998,6 +998,7 @@ MonoBehaviour: OtherPanel: {fileID: 163167163} SecondPanel: {fileID: 1662373578} PanelAbove: {fileID: 1293589669} + obj: {fileID: 2102416356} --- !u!58 &132185249 CircleCollider2D: m_ObjectHideFlags: 0 @@ -7402,6 +7403,7 @@ MonoBehaviour: OtherPanel: {fileID: 5331092055018478733, guid: 2b46aee216d4b304f8aebcb303ebf4f4, type: 3} SecondPanel: {fileID: 1662373578} PanelAbove: {fileID: 1293589669} + obj: {fileID: 158729764} --- !u!58 &277639225 CircleCollider2D: m_ObjectHideFlags: 0 @@ -25552,6 +25554,7 @@ MonoBehaviour: OtherPanel: {fileID: 5331092055018478733, guid: 2b46aee216d4b304f8aebcb303ebf4f4, type: 3} SecondPanel: {fileID: 1662373578} PanelAbove: {fileID: 1293589669} + obj: {fileID: 1027343184} --- !u!58 &584661740 CircleCollider2D: m_ObjectHideFlags: 0 @@ -36014,6 +36017,7 @@ MonoBehaviour: OtherPanel: {fileID: 5331092055018478733, guid: 2b46aee216d4b304f8aebcb303ebf4f4, type: 3} SecondPanel: {fileID: 1662373578} PanelAbove: {fileID: 1293589669} + obj: {fileID: 1265465282} --- !u!58 &805898527 CircleCollider2D: m_ObjectHideFlags: 0 @@ -36458,6 +36462,7 @@ MonoBehaviour: OtherPanel: {fileID: 626405956} SecondPanel: {fileID: 503724235} PanelAbove: {fileID: 1241490289} + obj: {fileID: 641696201} --- !u!58 &875629809 CircleCollider2D: m_ObjectHideFlags: 0 @@ -36621,6 +36626,7 @@ MonoBehaviour: OtherPanel: {fileID: 9124304227729624651, guid: e9cbfeb9e69af1245bc3180e86ff23f6, type: 3} SecondPanel: {fileID: 503724235} PanelAbove: {fileID: 1241490289} + obj: {fileID: 889215474} --- !u!58 &887082961 CircleCollider2D: m_ObjectHideFlags: 0 @@ -37687,6 +37693,7 @@ MonoBehaviour: OtherPanel: {fileID: 626405956} SecondPanel: {fileID: 503724235} PanelAbove: {fileID: 1241490289} + obj: {fileID: 8620305} --- !u!58 &1013260100 CircleCollider2D: m_ObjectHideFlags: 0 @@ -38046,6 +38053,7 @@ MonoBehaviour: OtherPanel: {fileID: 626405956} SecondPanel: {fileID: 503724235} PanelAbove: {fileID: 1241490289} + obj: {fileID: 68076400} --- !u!58 &1102795099 CircleCollider2D: m_ObjectHideFlags: 0 @@ -38503,6 +38511,7 @@ MonoBehaviour: OtherPanel: {fileID: 626405956} SecondPanel: {fileID: 503724235} PanelAbove: {fileID: 1241490289} + obj: {fileID: 242009510} --- !u!58 &1202265634 CircleCollider2D: m_ObjectHideFlags: 0 @@ -131310,6 +131319,7 @@ MonoBehaviour: OtherPanel: {fileID: 5331092055018478733, guid: 2b46aee216d4b304f8aebcb303ebf4f4, type: 3} SecondPanel: {fileID: 1662373578} PanelAbove: {fileID: 1293589669} + obj: {fileID: 926459323} --- !u!58 &1698721849 CircleCollider2D: m_ObjectHideFlags: 0 @@ -131631,6 +131641,7 @@ MonoBehaviour: OtherPanel: {fileID: 9124304227729624651, guid: e9cbfeb9e69af1245bc3180e86ff23f6, type: 3} SecondPanel: {fileID: 1662373578} PanelAbove: {fileID: 1293589669} + obj: {fileID: 622865435} --- !u!58 &1754993748 CircleCollider2D: m_ObjectHideFlags: 0 @@ -132898,6 +132909,7 @@ MonoBehaviour: OtherPanel: {fileID: 626405956} SecondPanel: {fileID: 503724235} PanelAbove: {fileID: 1241490289} + obj: {fileID: 682072029} --- !u!58 &2132075801 CircleCollider2D: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Item/PickableController.cs b/Assets/Scripts/Item/PickableController.cs index f97c6d2e..61dfd154 100644 --- a/Assets/Scripts/Item/PickableController.cs +++ b/Assets/Scripts/Item/PickableController.cs @@ -24,7 +24,7 @@ public class PickableController : MonoBehaviour InventoryManager.Instance.AddToInventory(this.item); string pickaxe = "picked"; PlayerPrefs.SetString("pickaxe1", pickaxe); - Destroy(gameObject); + gameObject.SetActive(false); } } } diff --git a/Assets/Scripts/QuitGame.cs b/Assets/Scripts/QuitGame.cs index f53d13b8..bffeee41 100644 --- a/Assets/Scripts/QuitGame.cs +++ b/Assets/Scripts/QuitGame.cs @@ -7,6 +7,6 @@ public class QuitGame : MonoBehaviour public void Exit() { Application.Quit(); - UnityEditor.EditorApplication.isPlaying = false; + //UnityEditor.EditorApplication.isPlaying = false; } } diff --git a/Assets/breakable.cs b/Assets/breakable.cs index 68f690e0..297c471d 100644 --- a/Assets/breakable.cs +++ b/Assets/breakable.cs @@ -25,7 +25,7 @@ public class breakable : MonoBehaviour int rock = PlayerPrefs.GetInt("rock"); if(rock == 0) { - Destroy(gameObject); + gameObject.SetActive(false); } } @@ -33,7 +33,7 @@ public class breakable : MonoBehaviour { if (timeToBreak == true){ PlayerPrefs.SetInt("rock", 0); - Destroy(gameObject); + gameObject.SetActive(false); } yield return new WaitForSeconds(1); var em = collisionParticleSystem.emission; diff --git a/UserSettings/EditorUserSettings.asset b/UserSettings/EditorUserSettings.asset index fe31a79a..78a67708 100644 --- a/UserSettings/EditorUserSettings.asset +++ b/UserSettings/EditorUserSettings.asset @@ -24,16 +24,16 @@ EditorUserSettings: value: 22424703114646680e0b0227036c72111f19352f223d667d6d0a1532f0e1372ce7f518e8ea3f7129370bfb25 flags: 0 RecentlyUsedScenePath-6: - value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d + value: 22424703114646680e0b0227036c7c1100123d24383a273e2e2c5326ece92021 flags: 0 RecentlyUsedScenePath-7: value: 22424703114646680e0b0227036c7c1100123d24383a273e2e2c5326ece92021 flags: 0 RecentlyUsedScenePath-8: - value: 22424703114646680e0b0227036c7c1100123d24383a273e2e2c5326ece92021 + value: 22424703114646680e0b0227036c72111f1958072926337e38271427fb flags: 0 RecentlyUsedScenePath-9: - value: 22424703114646680e0b0227036c72111f1958072926337e38271427fb + value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d flags: 0 vcSharedLogLevel: value: 0d5e400f0650