81 lines
2.6 KiB
C#
81 lines
2.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
/*
|
|
* <summary>A replacement for the Item class in VR contexts.</summary>
|
|
*/
|
|
[RequireComponent(typeof(Burnable))]
|
|
public class ItemVR : MonoBehaviour {
|
|
public BurnQuality IgnitedQuality;
|
|
public float IgniteDuration;
|
|
public bool Ignited = false;
|
|
public float TorchDuration;
|
|
public float TorchWarnDuration;
|
|
|
|
[Header("Burning indicators")]
|
|
public GameObject StickObject;
|
|
public GameObject TorchObject;
|
|
public ParticleSystem FireParticles;
|
|
public Light TorchLight;
|
|
public Color WarnColor;
|
|
|
|
[Header("Runtime values")]
|
|
public float TorchFuel;
|
|
|
|
private Burnable Burnable;
|
|
private int BurningSourceCount = 0;
|
|
private float IgnitionStartTime = -1;
|
|
private Color NormalColor;
|
|
|
|
private void Start() {
|
|
Burnable = GetComponent<Burnable>();
|
|
NormalColor = TorchLight.color;
|
|
TorchObject.SetActive(Ignited);
|
|
StickObject.SetActive(!Ignited);
|
|
}
|
|
|
|
private void Update() {
|
|
if (Ignited && TorchLight.enabled) {
|
|
TorchFuel -= Time.deltaTime;
|
|
if (TorchFuel < TorchWarnDuration) {
|
|
TorchLight.color = Color.Lerp(TorchLight.color, WarnColor, 5f * Time.deltaTime);
|
|
} else {
|
|
TorchLight.color = Color.Lerp(TorchLight.color, NormalColor, 5f * Time.deltaTime);
|
|
}
|
|
if (TorchFuel <= 0) {
|
|
FireParticles.Stop();
|
|
TorchLight.range = Mathf.Lerp(TorchLight.range, 0, 10f * Time.deltaTime);
|
|
if (TorchLight.range < 0.01f) {
|
|
TorchLight.enabled = false;
|
|
}
|
|
}
|
|
} else if (!Ignited && IgnitionStartTime != -1 && Time.time - IgnitionStartTime >= IgniteDuration) {
|
|
Ignited = true;
|
|
TorchFuel = TorchDuration;
|
|
TorchObject.SetActive(true);
|
|
FireParticles.Play();
|
|
StickObject.SetActive(false);
|
|
Burnable.Quality = IgnitedQuality;
|
|
}
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider collider) {
|
|
if (!Ignited && collider.gameObject.layer == LayerMask.NameToLayer("Fire")) {
|
|
if (BurningSourceCount == 0) {
|
|
IgnitionStartTime = Time.time;
|
|
}
|
|
BurningSourceCount++;
|
|
}
|
|
}
|
|
|
|
private void OnTriggerExit(Collider collider) {
|
|
if (!Ignited && collider.gameObject.layer == LayerMask.NameToLayer("Fire")) {
|
|
BurningSourceCount--;
|
|
if (BurningSourceCount == 0) {
|
|
IgnitionStartTime = -1;
|
|
}
|
|
}
|
|
}
|
|
}
|