1
0
mirror of synced 2024-12-12 06:21:04 +01:00
WACVR/Assets/Script/PanelThirdPersonButton.cs
msk 65a8ee2770 more ctrlpnl
- moved panel for easier access\
- gave third-person toggle its own code
- refactor panel button code
- instead of lock all buttons, hide non-game buttons
2022-05-23 18:25:05 -07:00

42 lines
928 B
C#

using System;
using System.Runtime.InteropServices;
using UnityEngine;
using WindowsInput.Native;
[RequireComponent(typeof(AudioSource))]
public class PanelThirdPersonButton : MonoBehaviour
{
public bool isTP;
private Renderer cr;
public GameObject tpCamera;
private AudioSource audioSrc;
private static AudioClip btnSound;
void Start()
{
btnSound = Resources.Load<AudioClip>("Audio/button press");
audioSrc = GetComponent<AudioSource>();
audioSrc.playOnAwake = false;
audioSrc.clip = btnSound;
cr = GetComponent<Renderer>();
SetTP(isTP);
}
private void OnTriggerEnter(Collider other)
{
audioSrc.Play();
isTP = !isTP;
SetTP(isTP);
}
private void SetTP(bool state)
{
isTP = state;
cr.material.color = state ? Color.green : Color.red;
tpCamera?.SetActive(state);
}
}