holopy3/Assets/Scripts/Blinky.cs

47 lines
1 KiB
C#
Raw Normal View History

2021-01-28 12:07:52 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Blinky : MonoBehaviour
{
private MeshRenderer renderer;
private void OnEnable()
{
Valve.VR.InteractionSystem.Player.OnHeadsetOn += ShowPlayer;
Valve.VR.InteractionSystem.Player.OnHeadsetOff += HidePlayer;
}
private void OnDisable()
{
Valve.VR.InteractionSystem.Player.OnHeadsetOn -= ShowPlayer;
Valve.VR.InteractionSystem.Player.OnHeadsetOff -= HidePlayer;
}
// Start is called before the first frame update
void Start()
{
renderer = GetComponent<MeshRenderer>();
StartCoroutine("Blink");
}
private IEnumerator Blink()
{
while (true)
{
yield return new WaitForSeconds(0.2f);
renderer.enabled = !renderer.enabled;
}
}
private void ShowPlayer()
{
StartCoroutine("Blink");
}
private void HidePlayer()
{
StopAllCoroutines();
renderer.enabled = false;
}
}