A lot of errors fixed, boundries and narrations and items working properly

Most things work properly, just force sensor that is not working properly
This commit is contained in:
Nicklas 2024-03-11 20:13:48 +01:00
parent 66378208d7
commit 826ab478f7
14 changed files with 178 additions and 81 deletions

BIN
.DS_Store vendored

Binary file not shown.

BIN
Assets/.DS_Store vendored

Binary file not shown.

BIN
Assets/1OurAudioNarrationFiles/.DS_Store vendored Normal file

Binary file not shown.

@ -14,15 +14,20 @@ public class BoundAirScript : MonoBehaviour
public bool canActivateAir = false;
public bool narrationHasPlayed = false;
private bool secondNarrationHasPlayed = false;
public AudioSource audioSource;
public AudioClip narrationClip;
public AudioClip narrationClipTwo;
public GameObject windObjectToCollect;
private bool objectHasBeenCollected = false;
//Boundary control
private BoundaryControlScript boundControl;
public BoundaryControlScript boundControl;
// Start is called before the first frame update
void Start()
@ -36,7 +41,7 @@ public class BoundAirScript : MonoBehaviour
{
if (other.CompareTag("BoundHMD") && !isWindActive && !narrationHasPlayed) //
{
boundControl.tempRemoveBoundary("Air");
boundControl.TempRemoveBoundary("Air");
narrationHasPlayed = true;
//Play narration
@ -87,10 +92,22 @@ public class BoundAirScript : MonoBehaviour
StartCoroutine(ResetParticleSpeed(5.0f)); // Assuming gesture lasts for * seconds
//Insert second narration here
windObjectToCollect.SetActive(true);
audioSource.PlayOneShot(narrationClipTwo);
//StartCoroutine(SecondNarration());
}
/*IEnumerator SecondNarration()
{
yield return new WaitForSeconds(narrationClipTwo.length);
}*/
IEnumerator ResetParticleSpeed(float delay)
{
yield return new WaitForSeconds(delay);
@ -127,15 +144,14 @@ public class BoundAirScript : MonoBehaviour
public void stationCompleted()
{
StartCoroutine(RemoveCollectedItem());
boundControl.removeBoundary("Fire");
boundControl.reactivateBoundary("Fire");
//Insert functionality for starting counter narration etc
windObjectToCollect.SetActive(false);
boundControl.ReactivateBoundary();
boundControl.RemoveBoundary("Air");
}
IEnumerator RemoveCollectedItem()
{
yield return new WaitForSeconds(2.0f);
windObjectToCollect.SetActive(false);
}
}

@ -15,9 +15,11 @@ public class BoundEarthScript : MonoBehaviour
public GameObject earthObjectToCollect;
private bool objectHasBeenCollected = false;
//Boundary control
private BoundaryControlScript boundControl;
public BoundaryControlScript boundControl;
//Use Yield return to like not make it start instantly????
public void OnTriggerEnter(Collider other)
@ -27,7 +29,7 @@ public class BoundEarthScript : MonoBehaviour
{
//Removing other bounds temporarily
boundControl.tempRemoveBoundary("Earth");
boundControl.TempRemoveBoundary("Earth");
//Play narration
StartCoroutine(NarrationAndSignalCoroutine());
@ -64,16 +66,14 @@ public class BoundEarthScript : MonoBehaviour
public void stationCompleted()
{
StartCoroutine(RemoveCollectedItem());
boundControl.removeBoundary("Earth");
boundControl.reactivateBoundary("Earth");
//Insert functionality for starting counter narration etc
earthObjectToCollect.SetActive(false);
boundControl.ReactivateBoundary();
boundControl.RemoveBoundary("Earth");
}
IEnumerator RemoveCollectedItem()
{
yield return new WaitForSeconds(2.0f);
earthObjectToCollect.SetActive(false);
}
}

@ -13,20 +13,22 @@ public class BoundFireScript : MonoBehaviour
public GameObject fireObjectToCollect;
private bool objectHasBeenCollected = false;
//Object to collect found in Fire collision script
//Boundary control
private BoundaryControlScript boundControl;
public BoundaryControlScript boundControl;
//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) //
{
//Removing other bounds temporarily
boundControl.tempRemoveBoundary("Fire");
boundControl.TempRemoveBoundary("Fire");
//Play narration
StartCoroutine(NarrationAndSignalCoroutine());
@ -44,26 +46,38 @@ public class BoundFireScript : MonoBehaviour
}
public void CollectFireObject()
{
StartCoroutine(SecondNarrationAndObject());
audioSource.PlayOneShot(narrationClipTwo);
fireObjectToCollect.SetActive(true);
}
IEnumerator SecondNarrationAndObject()
{
audioSource.PlayOneShot(narrationClipTwo);
fireObjectToCollect.SetActive(true);
yield return new WaitForSeconds(narrationClipTwo.length);
}
//Method to remove the boundary when station has been completed.
//Start through Unity event wrapper for when item to collect is selected.
//Make it a coroutine like so that it will wait 2 sec before removing
//the item to collect (now it goes away instantly)
//Method for controlling when the item is grabbed
public void stationCompleted()
{
StartCoroutine(RemoveCollectedItem());
boundControl.removeBoundary("Fire");
boundControl.reactivateBoundary("Fire");
//Insert functionality for starting counter narration etc
fireObjectToCollect.SetActive(false);
boundControl.ReactivateBoundary();
boundControl.RemoveBoundary("Fire");
}
IEnumerator RemoveCollectedItem()
{
yield return new WaitForSeconds(2.0f);
fireObjectToCollect.SetActive(false);
}
}

@ -14,9 +14,11 @@ public class BoundWaterScript : MonoBehaviour
public GameObject waterObjectToCollect;
private bool objectHasBeenCollected = false;
//Boundary control
private BoundaryControlScript boundControl;
public BoundaryControlScript boundControl;
//Use Yield return to like not make it start instantly????
@ -28,7 +30,7 @@ public class BoundWaterScript : MonoBehaviour
//TestWater.SetActive(true);
//Removing other bounds temporarily
boundControl.tempRemoveBoundary("Water");
boundControl.TempRemoveBoundary("Water");
//Play narration
StartCoroutine(NarrationAndSignalCoroutine());
@ -54,7 +56,6 @@ public class BoundWaterScript : MonoBehaviour
waterObjectToCollect.SetActive(true);
audioSource.PlayOneShot(narrationClipTwo);
dropHasAppeared = true;
stationCompleted();
}
}
@ -65,15 +66,13 @@ public class BoundWaterScript : MonoBehaviour
public void stationCompleted()
{
StartCoroutine(RemoveCollectedItem());
boundControl.removeBoundary("Water");
boundControl.reactivateBoundary("Water");
//Insert functionality for starting counter narration etc
waterObjectToCollect.SetActive(false);
boundControl.ReactivateBoundary();
boundControl.RemoveBoundary("Water");
}
IEnumerator RemoveCollectedItem()
{
yield return new WaitForSeconds(2.0f);
waterObjectToCollect.SetActive(false);
}
}

@ -14,13 +14,18 @@ public class BoundaryControlScript : MonoBehaviour
private bool waterFinished = false;
private bool fireFinished = false;
private bool airHasBeenCollected = false;
private bool earthHasBeenCollected = false;
private bool waterHasBeenCollected = false;
private bool fireHasBeenCollected = false;
private int collectionCounter = 0;
// Add references for the AudioSource and narration clips
public AudioSource narrationSource;
public AudioClip[] narrationClips; // Ensure this array is populated in the Inspector with your narration clips
public void tempRemoveBoundary(string bound)
public void TempRemoveBoundary(string bound)
{
if (bound == "Air")
{
@ -48,7 +53,7 @@ public class BoundaryControlScript : MonoBehaviour
}
}
public void reactivateBoundary(string bound)
public void ReactivateBoundary()
{
if (!airFinished)
{
@ -71,34 +76,38 @@ public class BoundaryControlScript : MonoBehaviour
}
}
public void removeBoundary(string bound)
public void RemoveBoundary(string bound)
{
if (bound == "Air")
if (bound == "Air" && !airHasBeenCollected)
{
airFinished = true;
collectionCounter++;
PlayCollectionNarration();
airHasBeenCollected = true;
airBoundary.SetActive(false);
}
else if (bound == "Earth")
else if (bound == "Earth" && !earthHasBeenCollected)
{
earthFinished = true;
collectionCounter++;
PlayCollectionNarration();
earthHasBeenCollected = true;
earthBoundary.SetActive(false);
}
else if (bound == "Water")
else if (bound == "Water" && !waterHasBeenCollected)
{
waterFinished = true;
collectionCounter++;
PlayCollectionNarration();
waterHasBeenCollected = true;
waterBoundary.SetActive(false);
}
else if (bound == "Fire")
else if (bound == "Fire" && !fireHasBeenCollected)
{
fireFinished = true;
collectionCounter++;
PlayCollectionNarration();
fireHasBeenCollected = true;
fireBoundary.SetActive(false);
}
}
@ -106,6 +115,7 @@ public class BoundaryControlScript : MonoBehaviour
{
if (collectionCounter > 0 && collectionCounter <= narrationClips.Length)
{
narrationSource.Stop();
narrationSource.clip = narrationClips[collectionCounter - 1];
narrationSource.Play();
}

@ -11,7 +11,7 @@ public class ConnectUnityWithSensors : MonoBehaviour
//public AudioSource audioSource; // Assign in inspector
//public AudioClip narrationClip; // Assign in inspector
//
public string esp32IPAddress = "10.204.0.249"; // Assign your ESP32 IP Address
public string esp32IPAddress = "10.204.0.248"; // Assign your ESP32 IP Address
public string esp32WebsocketPort = "81"; // Assign your ESP32 WebSocket port, typically "81"
private bool forceDataReceived = false;

@ -10,7 +10,7 @@ public class FireCollisionAudioScript : MonoBehaviour
public GameObject fireBigger;
public GameObject fireEvenBigger;
private BoundFireScript boundFireScript;
public BoundFireScript boundFireScript;
private bool isFireBigger = false;
@ -21,11 +21,12 @@ public class FireCollisionAudioScript : MonoBehaviour
{
audioPlayerGround.Play();
}
else if (collision.gameObject.tag == "CampFireTag" && !isFireBigger) {
audioPlayerFire.Play();
else if (collision.gameObject.tag == "CampFireTag" && !isFireBigger && boundFireScript.narrationHasFinished) {
audioPlayerFire.Play(); //Add more dramatic audio
fireBigger.SetActive(true);
isFireBigger = true;
boundFireScript.fireObjectToCollect.SetActive(true);
boundFireScript.CollectFireObject();
} /*else if (collision.gameObject.tag == "CampFireTag" && isFireBigger)
{
fireEvenBigger.SetActive(true);

@ -75,6 +75,10 @@ public class WaterConnectUnityWithSensors : MonoBehaviour
}
}
//Failsafe in case something goes wrong (Get key down to make it so if the sensor
//doesnt work or is giving issues we can control it somehow (but how if we use apk lol????)
}

Binary file not shown.

@ -1,37 +1,85 @@
#include <Ultrasonic.h>
#include <ArduinoWebsockets.h>
#include <WiFi.h>
// Define the pins for the HC-SR04
const int trigPin = A5; // Replace with the GPIO pin connected to the Trig pin
const int echoPin = A1; // Replace with the GPIO pin connected to the Echo pin
const char* ssid = "dsv-extrality-lab"; // Change to your WiFi network name
const char* password = "expiring-unstuck-slider"; // Change to your WiFi password
Ultrasonic ultrasonic(trigPin, echoPin);
using namespace websockets;
WebsocketsServer server;
WebsocketsClient client;
const int trigPin = A5; // Change to the GPIO pin connected to the Trig pin of the HC-SR04
const int echoPin = A1; // Change to the GPIO pin connected to the Echo pin of the HC-SR04
void setup() {
Serial.begin(115200);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.print("Connected to WiFi. IP Address: ");
Serial.println(WiFi.localIP());
server.listen(81);
Serial.println("WebSocket server started.");
}
void loop() {
// Trigger the sensor
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(20); // Adjust this value
digitalWrite(trigPin, LOW);
// Read the echo pulse duration
unsigned long duration = pulseIn(echoPin, HIGH);
if (server.poll()) {
client = server.accept();
Serial.println("Client connected...");
// Calculate distance in centimeters
float distance = duration * 0.0343 / 2.0;
while (client.available()) {
WebsocketsMessage msg = client.readBlocking();
Serial.print("Got Message: ");
Serial.println(msg.data());
// Print the distance to the Serial Monitor
Serial.print("Duration: ");
Serial.print(duration);
Serial.print(" microseconds, Distance: ");
Serial.print(distance);
Serial.println(" cm");
if (msg.data().equalsIgnoreCase("Need Distance")) {
Serial.println("Measuring distance...");
// Trigger the sensor
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(20); // Adjust this value
digitalWrite(trigPin, LOW);
delay(1000); // Adjust the delay based on your needs
}
// Read the echo pulse duration
unsigned long duration = pulseIn(echoPin, HIGH);
// Calculate distance in centimeters
int distance = duration * 0.0343 / 2.0;
// Print the distance to the Serial Monitor
Serial.print("Duration: ");
Serial.print(duration);
Serial.print(" microseconds, Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(1000);
// Define a close distance threshold, for example, 10 cm
if (distance > 0 && distance < 10) {
// If the object is within the threshold, send a signal to Unity
Serial.println("Object is close. Sending signal to Unity...");
//client.send("ObjectClose");
client.send(String(distance));
} else {
// Optional: Send a different signal if the object is not within the threshold
//client.send("ObjectFar");
}
}
}
client.close();
}
}

@ -1447,7 +1447,7 @@ Transform:
m_GameObject: {fileID: 140392492}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 7.2416973, y: -2.2543073, z: -7.309}
m_LocalPosition: {x: 7.2416973, y: -2.2543073, z: -6.753239}
m_LocalScale: {x: 0.1, y: 0.1, z: 0.1}
m_ConstrainProportionsScale: 1
m_Children: []
@ -3022,7 +3022,7 @@ PrefabInstance:
- target: {fileID: 7809210389736015259, guid: 3a9b7854188d4405280e2aee6b228fc7,
type: 3}
propertyPath: m_LocalPosition.x
value: 2.084
value: 3.75
objectReference: {fileID: 0}
- target: {fileID: 7809210389736015259, guid: 3a9b7854188d4405280e2aee6b228fc7,
type: 3}
@ -3032,7 +3032,7 @@ PrefabInstance:
- target: {fileID: 7809210389736015259, guid: 3a9b7854188d4405280e2aee6b228fc7,
type: 3}
propertyPath: m_LocalPosition.z
value: -7.11
value: -6.117239
objectReference: {fileID: 0}
- target: {fileID: 7809210389736015259, guid: 3a9b7854188d4405280e2aee6b228fc7,
type: 3}
@ -5656,7 +5656,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 433046, guid: 6cd0c7b3308fc7544ad2a49e762470f0, type: 3}
propertyPath: m_LocalPosition.z
value: -7.615761
value: -7.06
objectReference: {fileID: 0}
- target: {fileID: 433046, guid: 6cd0c7b3308fc7544ad2a49e762470f0, type: 3}
propertyPath: m_LocalRotation.w
@ -6254,7 +6254,7 @@ PrefabInstance:
- target: {fileID: 7809210389736015259, guid: 3a9b7854188d4405280e2aee6b228fc7,
type: 3}
propertyPath: m_LocalPosition.z
value: -7.023761
value: -6.0309997
objectReference: {fileID: 0}
- target: {fileID: 7809210389736015259, guid: 3a9b7854188d4405280e2aee6b228fc7,
type: 3}
@ -6543,6 +6543,7 @@ MonoBehaviour:
audioPlayerGround: {fileID: 1439234604}
fireBigger: {fileID: 1439144478}
fireEvenBigger: {fileID: 308438764}
boundFireScript: {fileID: 634926189}
--- !u!1001 &500083348
PrefabInstance:
m_ObjectHideFlags: 0
@ -7573,7 +7574,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 466112, guid: 11a2bf50f579eff44aa4483864409a5e, type: 3}
propertyPath: m_LocalPosition.z
value: -7.6027613
value: -6.61
objectReference: {fileID: 0}
- target: {fileID: 466112, guid: 11a2bf50f579eff44aa4483864409a5e, type: 3}
propertyPath: m_LocalRotation.w
@ -8436,7 +8437,7 @@ Transform:
m_GameObject: {fileID: 579970255}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 7, y: 0.3216927, z: -7}
m_LocalPosition: {x: 7, y: 0.3216927, z: -6.444239}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
@ -8513,6 +8514,7 @@ MonoBehaviour:
narrationClip: {fileID: 8300000, guid: 687001dfd7eb24ccca4eb0e4db510dca, type: 3}
narrationClipTwo: {fileID: 8300000, guid: 8cb9b31b6571647878893398d64e6f19, type: 3}
windObjectToCollect: {fileID: 140392492}
boundControl: {fileID: 979159588}
--- !u!82 &579970260
AudioSource:
m_ObjectHideFlags: 0
@ -9323,7 +9325,7 @@ Transform:
m_GameObject: {fileID: 634926185}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 2.92, y: 0.3216927, z: -7.17}
m_LocalPosition: {x: 2.92, y: 0.3216927, z: -6.177239}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
@ -9395,6 +9397,7 @@ MonoBehaviour:
narrationClip: {fileID: 8300000, guid: 1eac976b1660e489a87b946acaf94b72, type: 3}
narrationClipTwo: {fileID: 8300000, guid: deff384217dfb4266aa229b913f8fd03, type: 3}
fireObjectToCollect: {fileID: 282901708}
boundControl: {fileID: 979159588}
--- !u!1001 &636743900
PrefabInstance:
m_ObjectHideFlags: 0
@ -12414,7 +12417,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 0ecd28734b48f4313bff134f6df55396, type: 3}
m_Name:
m_EditorClassIdentifier:
esp32IPAddress: 10.204.0.249
esp32IPAddress: 10.204.0.248
esp32WebsocketPort: 81
earthScript: {fileID: 1596973211}
--- !u!114 &979159587
@ -21797,7 +21800,7 @@ Transform:
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 2.462841, y: -1.1460905, z: -2.1307678}
m_LocalScale: {x: 10, y: 10, z: 10}
m_ConstrainProportionsScale: 0
m_ConstrainProportionsScale: 1
m_Children: []
m_Father: {fileID: 1617586590}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -21932,7 +21935,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 4123989887538996, guid: 590d927f63be3ce44bca618d073bb102, type: 3}
propertyPath: m_LocalPosition.z
value: -1.3
value: -0.92
objectReference: {fileID: 0}
- target: {fileID: 4123989887538996, guid: 590d927f63be3ce44bca618d073bb102, type: 3}
propertyPath: m_LocalRotation.w
@ -29494,6 +29497,7 @@ MonoBehaviour:
narrationClip: {fileID: 8300000, guid: 94cf8154f1b9943aba707d774a2821c7, type: 3}
narrationClipTwo: {fileID: 8300000, guid: d6a09c727429f41e1808479b9f8fd7a4, type: 3}
earthObjectToCollect: {fileID: 1726452294}
boundControl: {fileID: 979159588}
--- !u!1001 &1601739639
PrefabInstance:
m_ObjectHideFlags: 0
@ -30901,7 +30905,7 @@ PrefabInstance:
- target: {fileID: 1446526844107249175, guid: 8c24f4efc20ae488386410c07ba7ec0c,
type: 3}
propertyPath: m_LocalPosition.z
value: -7.95
value: -6.9572387
objectReference: {fileID: 0}
- target: {fileID: 1446526844107249175, guid: 8c24f4efc20ae488386410c07ba7ec0c,
type: 3}
@ -31574,6 +31578,7 @@ MonoBehaviour:
narrationClip: {fileID: 8300000, guid: 08211c0f27d2740228ddd729a21f516f, type: 3}
narrationClipTwo: {fileID: 8300000, guid: 86108e3698a924d59860ac92e3cc414a, type: 3}
waterObjectToCollect: {fileID: 297646202}
boundControl: {fileID: 979159588}
--- !u!1 &1726452294
GameObject:
m_ObjectHideFlags: 0
@ -37815,7 +37820,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 461792, guid: b5ea624fac4bcb44f96ad51d3745727e, type: 3}
propertyPath: m_LocalPosition.x
value: 8.47
value: 9.46
objectReference: {fileID: 0}
- target: {fileID: 461792, guid: b5ea624fac4bcb44f96ad51d3745727e, type: 3}
propertyPath: m_LocalPosition.y
@ -37823,7 +37828,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 461792, guid: b5ea624fac4bcb44f96ad51d3745727e, type: 3}
propertyPath: m_LocalPosition.z
value: -7.47
value: -6.124239
objectReference: {fileID: 0}
- target: {fileID: 461792, guid: b5ea624fac4bcb44f96ad51d3745727e, type: 3}
propertyPath: m_LocalRotation.w
@ -38183,7 +38188,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 4123989887538996, guid: 590d927f63be3ce44bca618d073bb102, type: 3}
propertyPath: m_LocalPosition.z
value: -1.3
value: -0.34
objectReference: {fileID: 0}
- target: {fileID: 4123989887538996, guid: 590d927f63be3ce44bca618d073bb102, type: 3}
propertyPath: m_LocalRotation.w