56 lines
1.2 KiB
C#
56 lines
1.2 KiB
C#
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;
|
|
|
|
public void Touched()
|
|
{
|
|
if (!isTouched)
|
|
{
|
|
GetComponent<Renderer>().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);
|
|
}
|
|
}
|
|
|
|
}
|