merge minigame to staging
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
<<<<<<<< HEAD:Assets/Project Files/Scripts/Helar/Items.meta
|
||||
guid: c509c0c7d8d7f2942a05792798d31fc0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
========
|
||||
guid: 1e00d72d45b494a4ea598ff34d46a589
|
||||
PrefabImporter:
|
||||
>>>>>>>> origin/joonasp_Milestone2:Assets/Project Files/Prefabs/JoonasP/EssenceNode.prefab.meta
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.Interaction.Toolkit;
|
||||
|
||||
public class EssenceNodeController : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private AudioSource chime;
|
||||
|
||||
|
||||
public bool isTouched;
|
||||
private bool followPlayer = false;
|
||||
private Transform player;
|
||||
|
||||
private float timer;
|
||||
private Material nodeMaterial;
|
||||
|
||||
private Coroutine decayCo;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
nodeMaterial = GetComponent<Renderer>().material;
|
||||
}
|
||||
|
||||
public void Touched()
|
||||
{
|
||||
if (!isTouched)
|
||||
{
|
||||
GetComponent<Renderer>().material.color = Color.cyan;
|
||||
chime.Play();
|
||||
isTouched = true;
|
||||
StopCoroutine(decayCo);
|
||||
}
|
||||
}
|
||||
|
||||
public void FollowPlayer()
|
||||
{
|
||||
followPlayer = true;
|
||||
player = GameObject.FindGameObjectWithTag("MainCamera").transform;
|
||||
StartCoroutine(Collect());
|
||||
|
||||
}
|
||||
|
||||
public void SetPitch(float value)
|
||||
{
|
||||
chime.pitch = value;
|
||||
}
|
||||
|
||||
public void SetTimer(float seconds)
|
||||
{
|
||||
timer = seconds;
|
||||
decayCo = StartCoroutine(Decay());
|
||||
}
|
||||
|
||||
|
||||
IEnumerator Collect()
|
||||
{
|
||||
yield return new WaitForSeconds(2f);
|
||||
//TODO: Update value in player inventory
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
IEnumerator Decay()
|
||||
{
|
||||
yield return new WaitForSeconds(timer);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!isTouched)
|
||||
{
|
||||
//A way to either linearly reduce the alpha value of color or fade the color to gray (must react to changing timer values)
|
||||
}
|
||||
|
||||
if (followPlayer)
|
||||
{
|
||||
transform.position = Vector3.Lerp(transform.position, new Vector3(player.position.x,player.position.y - 0.5f, player.position.z), Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c8d18c6d4425a674c921717bf08e59bd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
102
Assets/Project Files/Scripts/JoonasP/LeverController.cs
Normal file
102
Assets/Project Files/Scripts/JoonasP/LeverController.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.XR.Interaction.Toolkit;
|
||||
|
||||
public class LeverController : MonoBehaviour
|
||||
{
|
||||
private Transform pivot; //The lever will use a pivot point
|
||||
private Transform grabHand;
|
||||
private bool leverGrabbed;
|
||||
private bool eventCalled;
|
||||
private bool leverDown;
|
||||
|
||||
private Vector3 handDelta;
|
||||
private Vector3 lastPosition;
|
||||
|
||||
//These UnityEvent objects can be set in the inspector as any public methods from scripts
|
||||
[SerializeField]
|
||||
private UnityEvent onUp;
|
||||
[SerializeField]
|
||||
private UnityEvent onDown;
|
||||
|
||||
public float minAngle = 20f;
|
||||
public float maxAngle = 75f;
|
||||
|
||||
public float hapticAmplitude = 1f;
|
||||
public float hapticDuration = 0.1f;
|
||||
|
||||
public AudioSource upSound;
|
||||
public AudioSource downSound;
|
||||
|
||||
//This script cannot work with multiplayer, see CheckHand() method
|
||||
public Transform leftHand;
|
||||
public Transform rightHand;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
pivot = transform.parent;
|
||||
leverGrabbed = false;
|
||||
leverDown = false;
|
||||
pivot.eulerAngles = new Vector3(pivot.eulerAngles.x, pivot.eulerAngles.y, minAngle);
|
||||
leftHand = GameObject.Find("LeftHand Controller").transform;
|
||||
rightHand = GameObject.Find("RightHand Controller").transform;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (leverGrabbed)
|
||||
{
|
||||
handDelta = lastPosition - grabHand.position; //The vector of hand movement between frames
|
||||
pivot.RotateAround(pivot.position, pivot.forward, 200 * handDelta.y); //Is a Time.deltaTime multiplication needed here?
|
||||
|
||||
//Two following if statements set the up and down position angles and call events when angle is met
|
||||
//Only one event is called per grab because the logic is in the update method
|
||||
if(pivot.eulerAngles.z < minAngle)
|
||||
{
|
||||
pivot.eulerAngles = new Vector3(pivot.eulerAngles.x, pivot.eulerAngles.y, minAngle);
|
||||
if (leverDown)
|
||||
{
|
||||
onUp.Invoke();
|
||||
grabHand.gameObject.GetComponent<ActionBasedController>().SendHapticImpulse(hapticAmplitude, hapticDuration);
|
||||
if (upSound != null) upSound.Play();
|
||||
leverDown = false;
|
||||
}
|
||||
}
|
||||
else if(pivot.eulerAngles.z > maxAngle)
|
||||
{
|
||||
pivot.eulerAngles = new Vector3(pivot.eulerAngles.x, pivot.eulerAngles.y, maxAngle);
|
||||
if (!leverDown)
|
||||
{
|
||||
onDown.Invoke();
|
||||
grabHand.gameObject.GetComponent<ActionBasedController>().SendHapticImpulse(hapticAmplitude, hapticDuration);
|
||||
if (downSound != null) downSound.Play();
|
||||
leverDown = true;
|
||||
}
|
||||
}
|
||||
|
||||
lastPosition = grabHand.position;
|
||||
}
|
||||
}
|
||||
|
||||
public void GrabLever()
|
||||
{
|
||||
CheckHand();
|
||||
leverGrabbed = !leverGrabbed;
|
||||
handDelta = Vector3.zero;
|
||||
lastPosition = grabHand.position;
|
||||
eventCalled = false;
|
||||
}
|
||||
|
||||
private void CheckHand()
|
||||
{
|
||||
float leftDistance = Vector3.Distance(leftHand.position, transform.position);
|
||||
float rightDistance = Vector3.Distance(rightHand.position, transform.position);
|
||||
|
||||
if (leftDistance > rightDistance) grabHand = rightHand;
|
||||
else grabHand = leftHand;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
11
Assets/Project Files/Scripts/JoonasP/LeverController.cs.meta
Normal file
11
Assets/Project Files/Scripts/JoonasP/LeverController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 090ddea5aafb4e945868d2613c3bfbaa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
22
Assets/Project Files/Scripts/JoonasP/LeverEventTest.cs
Normal file
22
Assets/Project Files/Scripts/JoonasP/LeverEventTest.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class LeverEventTest : MonoBehaviour
|
||||
{
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
gameObject.GetComponent<Renderer>().material.color = Color.red;
|
||||
}
|
||||
|
||||
public void On()
|
||||
{
|
||||
gameObject.GetComponent<Renderer>().material.color = Color.green;
|
||||
}
|
||||
|
||||
public void Off()
|
||||
{
|
||||
gameObject.GetComponent<Renderer>().material.color = Color.red;
|
||||
}
|
||||
}
|
||||
11
Assets/Project Files/Scripts/JoonasP/LeverEventTest.cs.meta
Normal file
11
Assets/Project Files/Scripts/JoonasP/LeverEventTest.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0a90699fc7b10474aaac51ec87819dc6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
69
Assets/Project Files/Scripts/JoonasP/WellController.cs
Normal file
69
Assets/Project Files/Scripts/JoonasP/WellController.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class WellController : MonoBehaviour
|
||||
{
|
||||
public GameObject node;
|
||||
public int numberOfNodes = 5;
|
||||
private List<GameObject> nodes = new List<GameObject>();
|
||||
|
||||
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;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void StartMinigame()
|
||||
{
|
||||
player = GameObject.FindGameObjectWithTag("MainCamera").transform;
|
||||
Vector3 nodeSpawn = player.transform.position + (player.forward * 0.5f);
|
||||
nodeSpawn.y = player.transform.position.y;
|
||||
up = player.transform.up;
|
||||
right = player.transform.right;
|
||||
StartCoroutine(SpawnNode(nodeSpawn, 0.5f, 0));
|
||||
}
|
||||
|
||||
IEnumerator SpawnNode(Vector3 nodeSpawn, float pitch, int i)
|
||||
{
|
||||
if(i == numberOfNodes)
|
||||
{
|
||||
yield return new WaitForSeconds((despawnTime - spawnDelay) * 2); //Wait for all of the nodes to despawn
|
||||
foreach(GameObject node in nodes)
|
||||
{
|
||||
node.GetComponent<EssenceNodeController>().FollowPlayer();
|
||||
}
|
||||
nodes.Clear();
|
||||
|
||||
yield break;
|
||||
}
|
||||
|
||||
GameObject tempNode = Instantiate(node, nodeSpawn, Quaternion.identity);
|
||||
tempNode.GetComponent<EssenceNodeController>().SetTimer(2f);
|
||||
tempNode.GetComponent<AudioSource>().pitch = pitch;
|
||||
nodeSpawn = nodeSpawn + right * rightDistance + Random.Range(minDown, maxUp) * up;
|
||||
yield return new WaitForSeconds(spawnDelay);
|
||||
StartCoroutine(SpawnNode(nodeSpawn, pitch, i + 1));
|
||||
yield return new WaitForSeconds(despawnTime - spawnDelay);
|
||||
if (tempNode.GetComponent<EssenceNodeController>().isTouched)
|
||||
{
|
||||
nodes.Add(tempNode);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
transform.Rotate(new Vector3(10f, 10f, 10f) * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
11
Assets/Project Files/Scripts/JoonasP/WellController.cs.meta
Normal file
11
Assets/Project Files/Scripts/JoonasP/WellController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 580a2bc767950d54d9fdf84752500d7f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user