mirror of
https://github.com/muskit/H3VR-TNH-Quality-of-Life-Improvements.git
synced 2026-06-02 20:24:26 -07:00
64 lines
1.3 KiB
C#
64 lines
1.3 KiB
C#
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
namespace TNHQoLImprovements
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// Flash attached MeshRenderer the timer runs out.
|
||
|
|
/// </summary>
|
||
|
|
public class MeshRendererFlicker : MonoBehaviour
|
||
|
|
{
|
||
|
|
private bool initialized = false;
|
||
|
|
|
||
|
|
private float beginTime;
|
||
|
|
private float onLength;
|
||
|
|
private float offLength;
|
||
|
|
private float stateChangeTime = 0;
|
||
|
|
private bool visible = true;
|
||
|
|
|
||
|
|
private MeshRenderer mesh;
|
||
|
|
|
||
|
|
void Start()
|
||
|
|
{
|
||
|
|
mesh = GetComponent<MeshRenderer>();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void Init(float interval, float onToOffRatio = 0.5f, float beginAfter = 0)
|
||
|
|
{
|
||
|
|
beginTime = Time.time + beginAfter;
|
||
|
|
onLength = interval * onToOffRatio;
|
||
|
|
offLength = interval * (1 - onToOffRatio);
|
||
|
|
|
||
|
|
initialized = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
void Update()
|
||
|
|
{
|
||
|
|
if (!initialized || Time.time < beginTime)
|
||
|
|
return;
|
||
|
|
|
||
|
|
if (Time.time >= stateChangeTime)
|
||
|
|
{
|
||
|
|
visible = !visible;
|
||
|
|
mesh.enabled = visible;
|
||
|
|
|
||
|
|
if (visible) // set time to stay on
|
||
|
|
{
|
||
|
|
stateChangeTime = Time.time + onLength;
|
||
|
|
}
|
||
|
|
else // set time to stay off
|
||
|
|
{
|
||
|
|
stateChangeTime = Time.time + offLength;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
//if (Time.time >= stateChangeTime)
|
||
|
|
// {
|
||
|
|
// stateChangeTime = Time.time + interval;
|
||
|
|
// visible = !visible;
|
||
|
|
// mesh.enabled = visible;
|
||
|
|
// }
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|