Scripts for boundries created and managed.

Now the program can detect if user enters zone.
This commit is contained in:
Nicklas 2024-03-04 16:17:32 +01:00
parent f8f31189da
commit a0c2a60c30
14 changed files with 1272 additions and 35 deletions

@ -0,0 +1,123 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BoundAirScript : MonoBehaviour
{
public ParticleSystem masterEmitter; // Assign in the inspector
public ParticleSystem slaveEmitter; // Assign in the inspector
public GameObject moreSpirals;
private float defaultLifetime = 0.5f; // Default start lifetime, adjust as needed
public float fasterLifetime = 2.0f; // Example faster lifetime, adjust as needed
public bool isWindActive = false;
private bool canActivateAir = false;
public GameObject TestAir;
public AudioSource audioSource;
public AudioClip narrationClip;
// Start is called before the first frame update
void Start()
{
defaultLifetime = masterEmitter.main.startLifetime.constant;
}
//Use Yield return to like not make it start instantly????
public void OnTriggerEnter(Collider other)
{
if (other.CompareTag("BoundHMD")) //
{
Debug.Log("Entered Earth");
TestAir.SetActive(true);
//Play narration and remove other temp
StartCoroutine(NarrationAndSignalCoroutine());
canActivateAir = true;
}
}
/*public void OnTriggerExit(Collider other)
{
if (other.CompareTag("BoundHMD")) //
{
}
}*/
IEnumerator NarrationAndSignalCoroutine()
{
audioSource.PlayOneShot(narrationClip);
yield return new WaitForSeconds(narrationClip.length);
}
//Air effects
public void AdjustParticleSpeed()
{
if (!isWindActive && canActivateAir)
{
var masterMain = masterEmitter.main;
masterMain.startLifetime = fasterLifetime; // Adjust master emitter lifetime
var slaveMain = slaveEmitter.main;
slaveMain.duration = fasterLifetime; // Adjust slave emitter duration to match
// Restart the particle systems to apply the changes immediately
masterEmitter.Stop();
masterEmitter.Play();
slaveEmitter.Stop();
slaveEmitter.Play();
moreSpirals.SetActive(true);
isWindActive = true;
StartCoroutine(ResetParticleSpeed(5.0f)); // Assuming gesture lasts for * seconds
}
}
IEnumerator ResetParticleSpeed(float delay)
{
yield return new WaitForSeconds(delay);
// Reset particle system speed to default
AdjustParticleSpeedReset();
}
public void AdjustParticleSpeedReset()
{
var masterMain = masterEmitter.main;
masterMain.startLifetime = defaultLifetime; // Adjust master emitter lifetime
var slaveMain = slaveEmitter.main;
slaveMain.duration = defaultLifetime; // Adjust slave emitter duration to match
// Restart the particle systems to apply the changes immediately
masterEmitter.Stop();
masterEmitter.Play();
slaveEmitter.Stop();
slaveEmitter.Play();
moreSpirals.SetActive(false);
isWindActive = false;
canActivateAir = false;
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 08326b74dc55e449f9db5b90e65d5cb9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,32 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BoundEarthScript : MonoBehaviour
{
public GameObject TestEarth;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
//Use Yield return to like not make it start instantly????
public void OnTriggerEnter(Collider other)
{
if (other.CompareTag("BoundHMD")) //
{
Debug.Log("Entered Earth");
TestEarth.SetActive(true);
//Play narration and remove other temp
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cc0e3798309a94a59a7f394d52b61915
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,32 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BoundFireScript : MonoBehaviour
{
public GameObject TestFire;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
//Use Yield return to like not make it start instantly????
public void OnTriggerEnter(Collider other)
{
if (other.CompareTag("BoundHMD")) //
{
Debug.Log("Entered Fire");
TestFire.SetActive(true);
//Play narration and remove other temp
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: afeef29dbc53a4764a5da22a5577a58f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,32 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BoundWaterScript : MonoBehaviour
{
public GameObject TestWater;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
//Use Yield return to like not make it start instantly????
public void OnTriggerEnter(Collider other)
{
if (other.CompareTag("BoundHMD")) //
{
Debug.Log("Entered Water");
TestWater.SetActive(true);
//Play narration and remove other temp
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a08ac8c45c8c34d2892774a34ab9fef6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -20,7 +20,7 @@ public class ConnectUnityWithSensors : MonoBehaviour
void Start()
{
ConnectWithESP32();
//StartCoroutine(NarrationAndSignalCoroutine());
}
public void ConnectWithESP32()
@ -47,15 +47,7 @@ public class ConnectUnityWithSensors : MonoBehaviour
Debug.Log("Websocket state - " + ws.ReadyState);
}
/*IEnumerator NarrationAndSignalCoroutine()
{
audioSource.PlayOneShot(narrationClip);
yield return new WaitForSeconds(narrationClip.length);
if (ws.IsAlive)
{
ws.Send("Need Force");
}
}*/
void Update()
{

@ -0,0 +1,52 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameManagerScript : MonoBehaviour
{
public GameObject TestFire;
public GameObject TestAir;
public GameObject TestEarth;
public GameObject TestWater;
// Start is called before the first frame update
void Start()
{
Debug.Log("Hello World");
}
// Update is called once per frame
void Update()
{
}
//Use Yield return to like not make it start instantly????
public void OnTriggerEnter(Collider other)
{
if (other.CompareTag("BoundEarth")) //
{
Debug.Log("Entered Earth");
TestEarth.SetActive(true);
//Play narration and remove other temp
}
else if (other.CompareTag("BoundWater"))
{
Debug.Log("Entered Water");
TestWater.SetActive(true);
//Play narration and remove ot
}
else if (other.CompareTag("BoundFire"))
{
Debug.Log("Entered Fire");
TestFire.SetActive(true);
//Play narration and remove otehr temp
}
else if (other.CompareTag("BoundAir"))
{
Debug.Log("Entered Air");
TestAir.SetActive(true);
//Play narration and remove otehr temp
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a4f7787c3dc6a48fc926b4089740e305
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

@ -7,6 +7,11 @@ TagManager:
- Fire
- GroundTag
- CampFireTag
- BoundAir
- BoundFire
- BoundWater
- BoundEarth
- BoundHMD
layers:
- Default
- TransparentFX

@ -38,6 +38,7 @@ Library: /Users/nicklasbourelius/Unity Learn /NNMDETGroupProject/Temp/BurstOutpu
--assembly-defines=Unity.XR.Management;
--assembly-defines=Unity.XR.Oculus;
--assembly-defines=UnityEngine;
--assembly-defines=websocket-sharp;
--generate-link-xml=Temp/burst.link.xml
--temp-folder=/Users/nicklasbourelius/Unity Learn /NNMDETGroupProject/Temp/Burst
--key-folder=/Applications/Unity/Hub/Editor/2022.3.18f1/PlaybackEngines/AndroidPlayer
@ -85,6 +86,7 @@ Library: /Users/nicklasbourelius/Unity Learn /NNMDETGroupProject/Temp/BurstOutpu
--assembly-defines=Unity.XR.Management;
--assembly-defines=Unity.XR.Oculus;
--assembly-defines=UnityEngine;
--assembly-defines=websocket-sharp;
--generate-link-xml=Temp/burst.link.xml
--temp-folder=/Users/nicklasbourelius/Unity Learn /NNMDETGroupProject/Temp/Burst
--key-folder=/Applications/Unity/Hub/Editor/2022.3.18f1/PlaybackEngines/AndroidPlayer