From d7a10bfc4e485dce4689c6578947fc705846f879 Mon Sep 17 00:00:00 2001 From: Nicklas <145897592+nick7ass@users.noreply.github.com> Date: Fri, 8 Mar 2024 15:39:59 +0100 Subject: [PATCH] Trying to get water station to work, connecting with esp32. Issues on the side of the sensor right now. --- Assets/1OurScripts/BoundWaterScript.cs | 46 ++++++++++++++++++- .../WaterConnectUnityWithSensors.cs | 6 +-- Assets/Scenes/MainScene.unity | 7 ++- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/Assets/1OurScripts/BoundWaterScript.cs b/Assets/1OurScripts/BoundWaterScript.cs index 5f66d98..a4892d3 100644 --- a/Assets/1OurScripts/BoundWaterScript.cs +++ b/Assets/1OurScripts/BoundWaterScript.cs @@ -16,7 +16,10 @@ public class BoundWaterScript : MonoBehaviour public GameObject TestWater; - + public GameObject BoundFire; + public GameObject BoundEarth; + public GameObject BoundAir; + // Start is called before the first frame update void Start() { @@ -31,11 +34,50 @@ public class BoundWaterScript : MonoBehaviour //Use Yield return to like not make it start instantly???? public void OnTriggerEnter(Collider other) { - if (other.CompareTag("BoundHMD")) // + if (other.CompareTag("BoundHMD") && !narrationHasFinished && !narrationHasStarted) // { Debug.Log("Entered Water"); TestWater.SetActive(true); //Play narration and remove other temp + + BoundAir.SetActive(false); + BoundFire.SetActive(false); + BoundEarth.SetActive(false); + + StartCoroutine(NarrationAndSignalCoroutine()); + + } + } + + IEnumerator NarrationAndSignalCoroutine() + { + narrationHasStarted = true; + audioSource.PlayOneShot(narrationClip); + + yield return new WaitForSeconds(narrationClip.length); + + narrationHasFinished = true; + + } + + public void collectDistance() + { + if (narrationHasFinished && !dropHasAppeared) + { + //Force sensor + // if (ConnectUnityWithSensors.isForceDetected) + // { + //} + waterObjectToCollect.SetActive(true); + audioSource.PlayOneShot(narrationClipTwo); + dropHasAppeared = true; + + //Make these not go until narration has ended? + //Or make it so that these are not activated until the object has been collected + //Implement this for all of the different elements + BoundAir.SetActive(true); + BoundFire.SetActive(true); + BoundEarth.SetActive(true); } } diff --git a/Assets/1OurScripts/WaterConnectUnityWithSensors.cs b/Assets/1OurScripts/WaterConnectUnityWithSensors.cs index 7e6c5d3..2b8f8b5 100644 --- a/Assets/1OurScripts/WaterConnectUnityWithSensors.cs +++ b/Assets/1OurScripts/WaterConnectUnityWithSensors.cs @@ -56,7 +56,7 @@ public class WaterConnectUnityWithSensors : MonoBehaviour void Update() {//Change to Water script - if (waterScript.narrationHasFinished /*&& !waterScript.seedHasAppeared*/) + if (waterScript.narrationHasFinished && !waterScript.dropHasAppeared) { Debug.Log("Asking for distance."); @@ -64,11 +64,11 @@ public class WaterConnectUnityWithSensors : MonoBehaviour if (distanceDataReceived) { - if (receivedDistanceValue > 900) + if (receivedDistanceValue < 10) { Debug.Log("Distance threshold exceeded, action triggered."); isDistanceDetected = true; - //waterScript.methodNameDependingOnDistance(); + waterScript.collectDistance(); } distanceDataReceived = false; // Reset for the next message diff --git a/Assets/Scenes/MainScene.unity b/Assets/Scenes/MainScene.unity index 12bcf00..f2bafb6 100644 --- a/Assets/Scenes/MainScene.unity +++ b/Assets/Scenes/MainScene.unity @@ -31919,10 +31919,13 @@ MonoBehaviour: dropHasAppeared: 0 narrationHasStarted: 0 audioSource: {fileID: 171465764} - narrationClip: {fileID: 0} - narrationClipTwo: {fileID: 0} + narrationClip: {fileID: 8300000, guid: 09a27277c062f490ea6f7f06842f100f, type: 3} + narrationClipTwo: {fileID: 8300000, guid: 33724cce213214c3e8bba7e1c8b7f9de, type: 3} waterObjectToCollect: {fileID: 297646202} TestWater: {fileID: 707071907} + BoundFire: {fileID: 634926185} + BoundEarth: {fileID: 1596973207} + BoundAir: {fileID: 579970255} --- !u!1 &1726452294 GameObject: m_ObjectHideFlags: 0