| | | 1 | | using System.Collections; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using UnityEngine; |
| | | 4 | | |
| | | 5 | | public class VRNoPeeking : MonoBehaviour |
| | | 6 | | { |
| | | 7 | | [SerializeField] LayerMask collisionLayer; |
| | | 8 | | [SerializeField] float fadeSpeed; |
| | 12 | 9 | | [SerializeField] float sphereCheckSize = 0.15f; |
| | | 10 | | |
| | | 11 | | private Material cameraFadeMat; |
| | 12 | 12 | | private bool isCameraFadedOut = false; |
| | | 13 | | |
| | | 14 | | private void Awake() |
| | 0 | 15 | | { |
| | 0 | 16 | | cameraFadeMat = GetComponent<Renderer>().material; |
| | 0 | 17 | | } |
| | | 18 | | |
| | | 19 | | // Update is called once per frame |
| | | 20 | | void Update() |
| | 0 | 21 | | { |
| | 0 | 22 | | if (Physics.CheckSphere(transform.position, sphereCheckSize, collisionLayer, QueryTriggerInteraction.Ignore)) |
| | 0 | 23 | | { |
| | 0 | 24 | | CameraFade(1f); |
| | 0 | 25 | | isCameraFadedOut = true; |
| | 0 | 26 | | } |
| | | 27 | | else |
| | 0 | 28 | | { |
| | 0 | 29 | | if(!isCameraFadedOut) |
| | 0 | 30 | | { |
| | 0 | 31 | | return; |
| | | 32 | | } |
| | 0 | 33 | | CameraFade(0f); |
| | 0 | 34 | | } |
| | 0 | 35 | | } |
| | | 36 | | |
| | | 37 | | public void CameraFade(float targetAlpha) |
| | 0 | 38 | | { |
| | 0 | 39 | | var fadeValue = Mathf.MoveTowards(cameraFadeMat.GetFloat("_AlphaValue"), targetAlpha, Time.deltaTime * fadeSpeed |
| | 0 | 40 | | cameraFadeMat.SetFloat("_AlphaValue", fadeValue); |
| | | 41 | | |
| | 0 | 42 | | if(fadeValue <= 0.01f) |
| | 0 | 43 | | { |
| | 0 | 44 | | isCameraFadedOut = false; |
| | 0 | 45 | | } |
| | 0 | 46 | | } |
| | | 47 | | |
| | | 48 | | public bool IsCameraFadedOut() |
| | 0 | 49 | | { |
| | 0 | 50 | | return isCameraFadedOut; |
| | 0 | 51 | | } |
| | | 52 | | } |