2022-03-17 15:24:46 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.XR.Interaction.Toolkit;
|
|
|
|
|
|
|
|
public class EssenceNodeController : MonoBehaviour
|
|
|
|
{
|
2022-03-21 15:52:47 +00:00
|
|
|
[SerializeField]
|
|
|
|
private AudioSource chime;
|
2022-03-25 16:03:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
public bool isTouched;
|
|
|
|
private bool followPlayer = false;
|
|
|
|
private Transform player;
|
2022-03-21 15:52:47 +00:00
|
|
|
|
2022-03-28 09:52:41 +00:00
|
|
|
private float timer;
|
|
|
|
private Material nodeMaterial;
|
|
|
|
|
|
|
|
private Coroutine decayCo;
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
nodeMaterial = GetComponent<Renderer>().material;
|
|
|
|
}
|
|
|
|
|
2022-03-17 15:24:46 +00:00
|
|
|
public void Touched()
|
|
|
|
{
|
2022-03-25 16:03:38 +00:00
|
|
|
if (!isTouched)
|
|
|
|
{
|
|
|
|
GetComponent<Renderer>().material.color = Color.cyan;
|
|
|
|
chime.Play();
|
|
|
|
isTouched = true;
|
2022-03-28 09:52:41 +00:00
|
|
|
StopCoroutine(decayCo);
|
2022-03-25 16:03:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void FollowPlayer()
|
|
|
|
{
|
|
|
|
followPlayer = true;
|
|
|
|
player = GameObject.FindGameObjectWithTag("MainCamera").transform;
|
2022-03-28 09:52:41 +00:00
|
|
|
StartCoroutine(Collect());
|
2022-03-25 16:03:38 +00:00
|
|
|
|
2022-03-21 15:52:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetPitch(float value)
|
|
|
|
{
|
|
|
|
chime.pitch = value;
|
2022-03-17 15:24:46 +00:00
|
|
|
}
|
2022-03-25 16:03:38 +00:00
|
|
|
|
2022-03-28 09:52:41 +00:00
|
|
|
public void SetTimer(float seconds)
|
|
|
|
{
|
|
|
|
timer = seconds;
|
|
|
|
decayCo = StartCoroutine(Decay());
|
|
|
|
}
|
|
|
|
|
2022-03-25 16:03:38 +00:00
|
|
|
|
2022-03-28 09:52:41 +00:00
|
|
|
IEnumerator Collect()
|
2022-03-25 16:03:38 +00:00
|
|
|
{
|
|
|
|
yield return new WaitForSeconds(2f);
|
|
|
|
//TODO: Update value in player inventory
|
|
|
|
Destroy(gameObject);
|
|
|
|
}
|
|
|
|
|
2022-03-28 09:52:41 +00:00
|
|
|
IEnumerator Decay()
|
|
|
|
{
|
|
|
|
yield return new WaitForSeconds(timer);
|
|
|
|
Destroy(gameObject);
|
|
|
|
}
|
|
|
|
|
2022-03-25 16:03:38 +00:00
|
|
|
private void Update()
|
|
|
|
{
|
2022-03-28 09:52:41 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2022-03-25 16:03:38 +00:00
|
|
|
if (followPlayer)
|
|
|
|
{
|
|
|
|
transform.position = Vector3.Lerp(transform.position, new Vector3(player.position.x,player.position.y - 0.5f, player.position.z), Time.deltaTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-17 15:24:46 +00:00
|
|
|
}
|