Trying to get water station to work, connecting with esp32. Issues on the side of the sensor right now.

This commit is contained in:
Nicklas 2024-03-08 15:39:59 +01:00
parent e40aeb6302
commit d7a10bfc4e
3 changed files with 52 additions and 7 deletions

@ -16,7 +16,10 @@ public class BoundWaterScript : MonoBehaviour
public GameObject TestWater; public GameObject TestWater;
public GameObject BoundFire;
public GameObject BoundEarth;
public GameObject BoundAir;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
@ -31,11 +34,50 @@ public class BoundWaterScript : MonoBehaviour
//Use Yield return to like not make it start instantly???? //Use Yield return to like not make it start instantly????
public void OnTriggerEnter(Collider other) public void OnTriggerEnter(Collider other)
{ {
if (other.CompareTag("BoundHMD")) // if (other.CompareTag("BoundHMD") && !narrationHasFinished && !narrationHasStarted) //
{ {
Debug.Log("Entered Water"); Debug.Log("Entered Water");
TestWater.SetActive(true); TestWater.SetActive(true);
//Play narration and remove other temp //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);
} }
} }

@ -56,7 +56,7 @@ public class WaterConnectUnityWithSensors : MonoBehaviour
void Update() void Update()
{//Change to Water script {//Change to Water script
if (waterScript.narrationHasFinished /*&& !waterScript.seedHasAppeared*/) if (waterScript.narrationHasFinished && !waterScript.dropHasAppeared)
{ {
Debug.Log("Asking for distance."); Debug.Log("Asking for distance.");
@ -64,11 +64,11 @@ public class WaterConnectUnityWithSensors : MonoBehaviour
if (distanceDataReceived) if (distanceDataReceived)
{ {
if (receivedDistanceValue > 900) if (receivedDistanceValue < 10)
{ {
Debug.Log("Distance threshold exceeded, action triggered."); Debug.Log("Distance threshold exceeded, action triggered.");
isDistanceDetected = true; isDistanceDetected = true;
//waterScript.methodNameDependingOnDistance(); waterScript.collectDistance();
} }
distanceDataReceived = false; // Reset for the next message distanceDataReceived = false; // Reset for the next message

@ -31919,10 +31919,13 @@ MonoBehaviour:
dropHasAppeared: 0 dropHasAppeared: 0
narrationHasStarted: 0 narrationHasStarted: 0
audioSource: {fileID: 171465764} audioSource: {fileID: 171465764}
narrationClip: {fileID: 0} narrationClip: {fileID: 8300000, guid: 09a27277c062f490ea6f7f06842f100f, type: 3}
narrationClipTwo: {fileID: 0} narrationClipTwo: {fileID: 8300000, guid: 33724cce213214c3e8bba7e1c8b7f9de, type: 3}
waterObjectToCollect: {fileID: 297646202} waterObjectToCollect: {fileID: 297646202}
TestWater: {fileID: 707071907} TestWater: {fileID: 707071907}
BoundFire: {fileID: 634926185}
BoundEarth: {fileID: 1596973207}
BoundAir: {fileID: 579970255}
--- !u!1 &1726452294 --- !u!1 &1726452294
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0