using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using Valve.VR.InteractionSystem; namespace Display { public class LookStraightDisplay : MonoBehaviour { public Image circleImage; public float timeToLookStraight = 1.5f; private Color startColor = Color.white.ColorWithAlpha(100); private Color endColor = Color.green.ColorWithAlpha(100); private float startTime; private List positions; private List quaternions; private Transform camTransform; public delegate void DoneCallback(); public DoneCallback OnDone { get; set; } private void OnEnable() { circleImage = GetComponentInChildren(); ResetCircle(); var cam = Camera.main; if (cam == null) { throw new Exception("No camera available"); } camTransform = cam.transform; } private void ResetCircle() { circleImage.color = startColor; startTime = Time.time; } private void FixedUpdate() { Debug.Log($"GameObject.Layer = {gameObject.layer}"); var layerMask = 1 << gameObject.layer; if (Physics.Raycast(camTransform.position, camTransform.forward, out var hit, 2f, layerMask)) { Debug.DrawRay(camTransform.position, camTransform.forward*hit.distance, Color.green); Debug.Log($"Hit something ({hit.collider.gameObject.layer})"); } else { Debug.DrawRay(camTransform.position, camTransform.forward*2f, Color.red); Debug.Log("Hit nothing"); ResetCircle(); } } private void Update() { var timePassed = Time.time - startTime; var currentColor = Color.Lerp(startColor, endColor, timePassed / timeToLookStraight); circleImage.color = currentColor; if (timePassed >= timeToLookStraight) { OnDone(); gameObject.SetActive(false); Destroy(gameObject); } } } }