From 851b7ae0da7dff985836a14a88282de99bc45745 Mon Sep 17 00:00:00 2001 From: joonasp <56842740+Joonasp1@users.noreply.github.com> Date: Fri, 25 Mar 2022 18:03:38 +0200 Subject: [PATCH] essence minigame improvements --- .../Prefabs/JoonasP/EssenceNode.prefab | 3 +- .../Scripts/JoonasP/EssenceNodeController.cs | 38 ++++++++++++++++- .../Scripts/JoonasP/WellController.cs | 42 +++++++++++++++---- Assets/Scenes/JoonasP/SampleScene.unity | 16 ++++--- ProjectSettings/ProjectSettings.asset | 2 + 5 files changed, 84 insertions(+), 17 deletions(-) diff --git a/Assets/Project Files/Prefabs/JoonasP/EssenceNode.prefab b/Assets/Project Files/Prefabs/JoonasP/EssenceNode.prefab index f01b8914..b917d393 100644 --- a/Assets/Project Files/Prefabs/JoonasP/EssenceNode.prefab +++ b/Assets/Project Files/Prefabs/JoonasP/EssenceNode.prefab @@ -31,7 +31,7 @@ Transform: m_GameObject: {fileID: 3467985268477833302} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: -5.04, y: 1.396, z: -11.537} - m_LocalScale: {x: 0.1, y: 0.1, z: 0.1} + m_LocalScale: {x: 0.05, y: 0.05, z: 0.05} m_ConstrainProportionsScale: 1 m_Children: [] m_Father: {fileID: 0} @@ -203,6 +203,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: chime: {fileID: 965315076614651339} + isTouched: 0 --- !u!82 &965315076614651339 AudioSource: m_ObjectHideFlags: 0 diff --git a/Assets/Project Files/Scripts/JoonasP/EssenceNodeController.cs b/Assets/Project Files/Scripts/JoonasP/EssenceNodeController.cs index 49f79099..11bd1834 100644 --- a/Assets/Project Files/Scripts/JoonasP/EssenceNodeController.cs +++ b/Assets/Project Files/Scripts/JoonasP/EssenceNodeController.cs @@ -7,15 +7,49 @@ public class EssenceNodeController : MonoBehaviour { [SerializeField] private AudioSource chime; + + + public bool isTouched; + private bool followPlayer = false; + private Transform player; public void Touched() { - GetComponent().material.color = Color.cyan; - chime.Play(); + if (!isTouched) + { + GetComponent().material.color = Color.cyan; + chime.Play(); + isTouched = true; + } + } + + public void FollowPlayer() + { + followPlayer = true; + player = GameObject.FindGameObjectWithTag("MainCamera").transform; + StartCoroutine(Despawn()); + } public void SetPitch(float value) { chime.pitch = value; } + + + IEnumerator Despawn() + { + yield return new WaitForSeconds(2f); + //TODO: Update value in player inventory + Destroy(gameObject); + } + + private void Update() + { + if (followPlayer) + { + transform.position = Vector3.Lerp(transform.position, new Vector3(player.position.x,player.position.y - 0.5f, player.position.z), Time.deltaTime); + } + } + } diff --git a/Assets/Project Files/Scripts/JoonasP/WellController.cs b/Assets/Project Files/Scripts/JoonasP/WellController.cs index db11f163..902073e3 100644 --- a/Assets/Project Files/Scripts/JoonasP/WellController.cs +++ b/Assets/Project Files/Scripts/JoonasP/WellController.cs @@ -6,9 +6,17 @@ public class WellController : MonoBehaviour { public GameObject node; public int numberOfNodes = 5; + private List nodes = new List(); + + public float spawnDelay; + //public float despawnTime; + private Transform player; + public float rightDistance = 0.2f; //Distance between spawned nodes + public float maxUp = 0.2f; //Maximum up shift between orbs + public float minDown = -0.2f; //Same but for down private Vector3 right; private Vector3 up; @@ -24,22 +32,40 @@ public class WellController : MonoBehaviour nodeSpawn.y = player.transform.position.y; up = player.transform.up; right = player.transform.right; - StartCoroutine(SpawnNode(nodeSpawn, 0)); + StartCoroutine(SpawnNode(nodeSpawn, 0.5f, 0)); } - IEnumerator SpawnNode(Vector3 nodeSpawn, int i) + IEnumerator SpawnNode(Vector3 nodeSpawn, float pitch, int i) { - if(i == numberOfNodes) yield break; + if(i == numberOfNodes) + { + foreach(GameObject node in nodes) + { + node.GetComponent().FollowPlayer(); + } + nodes.Clear(); + + yield break; + } GameObject tempNode = Instantiate(node, nodeSpawn, Quaternion.identity); - tempNode.GetComponent().pitch += (i * (1f / numberOfNodes)); - nodeSpawn = nodeSpawn + right * 0.2f + Random.Range(-0.2f, 0.2f) * up; - yield return new WaitForSeconds(2f); - StartCoroutine(SpawnNode(nodeSpawn, i+1)); + tempNode.GetComponent().pitch = pitch; + nodeSpawn = nodeSpawn + right * rightDistance + Random.Range(minDown, maxUp) * up; + yield return new WaitForSeconds(spawnDelay); + if (tempNode.GetComponent().isTouched) + { + nodes.Add(tempNode); + StartCoroutine(SpawnNode(nodeSpawn, pitch + 0.1f, i + 1)); + } + else + { + Destroy(tempNode); + StartCoroutine(SpawnNode(nodeSpawn, pitch, i + 1)); + } } private void Update() { - transform.Rotate(0.5f, 0.5f, 0.5f); + transform.Rotate(new Vector3(10f, 10f, 10f) * Time.deltaTime); } } diff --git a/Assets/Scenes/JoonasP/SampleScene.unity b/Assets/Scenes/JoonasP/SampleScene.unity index 1f091428..4822c89a 100644 --- a/Assets/Scenes/JoonasP/SampleScene.unity +++ b/Assets/Scenes/JoonasP/SampleScene.unity @@ -151,6 +151,10 @@ MonoBehaviour: m_EditorClassIdentifier: node: {fileID: 3467985268477833302, guid: 1e00d72d45b494a4ea598ff34d46a589, type: 3} numberOfNodes: 5 + spawnDelay: 1 + rightDistance: 0.1 + maxUp: 0.2 + minDown: -0.2 --- !u!114 &175686037 stripped MonoBehaviour: m_CorrespondingSourceObject: {fileID: 7543052554150911968, guid: 8f5582064724dbc45bc5c3432899f9c1, @@ -321,27 +325,27 @@ PrefabInstance: - target: {fileID: 7543052554475355072, guid: 8f5582064724dbc45bc5c3432899f9c1, type: 3} propertyPath: m_LocalPosition.z - value: -12.049 + value: -11.236 objectReference: {fileID: 0} - target: {fileID: 7543052554475355072, guid: 8f5582064724dbc45bc5c3432899f9c1, type: 3} propertyPath: m_LocalRotation.w - value: 0 + value: 0.6532815 objectReference: {fileID: 0} - target: {fileID: 7543052554475355072, guid: 8f5582064724dbc45bc5c3432899f9c1, type: 3} propertyPath: m_LocalRotation.x - value: 0.38268343 + value: -0.27059805 objectReference: {fileID: 0} - target: {fileID: 7543052554475355072, guid: 8f5582064724dbc45bc5c3432899f9c1, type: 3} propertyPath: m_LocalRotation.y - value: 0.92387956 + value: -0.6532815 objectReference: {fileID: 0} - target: {fileID: 7543052554475355072, guid: 8f5582064724dbc45bc5c3432899f9c1, type: 3} propertyPath: m_LocalRotation.z - value: 0 + value: 0.27059805 objectReference: {fileID: 0} - target: {fileID: 7543052554475355072, guid: 8f5582064724dbc45bc5c3432899f9c1, type: 3} @@ -351,7 +355,7 @@ PrefabInstance: - target: {fileID: 7543052554475355072, guid: 8f5582064724dbc45bc5c3432899f9c1, type: 3} propertyPath: m_LocalEulerAnglesHint.y - value: 180 + value: -90 objectReference: {fileID: 0} - target: {fileID: 7543052554475355072, guid: 8f5582064724dbc45bc5c3432899f9c1, type: 3} diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 4c1723be..a4ad741a 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -155,6 +155,8 @@ PlayerSettings: - {fileID: 0} - {fileID: 0} - {fileID: 0} + - {fileID: 0} + - {fileID: 0} metroInputSource: 0 wsaTransparentSwapchain: 0 m_HolographicPauseOnTrackingLoss: 1