Heroes_of_Hiis/Assets/Project Files/Scripts/JoonasP/EssenceNodeController.cs

56 lines
1.2 KiB
C#
Raw Normal View History

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-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;
}
}
public void FollowPlayer()
{
followPlayer = true;
player = GameObject.FindGameObjectWithTag("MainCamera").transform;
StartCoroutine(Despawn());
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
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);
}
}
2022-03-17 15:24:46 +00:00
}