47 lines
1 KiB
C#
47 lines
1 KiB
C#
|
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;
|
|||
|
}
|
|||
|
}
|