// Update is called once per frame void Update() { Ray ray = cam.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0)); RaycastHit hit; if (Physics.Raycast(ray, out hit, Distance)) { InteractForAnimation interactor = hit.collider.GetComponent <InteractForAnimation>(); if (interactor != null && interactor.CanInteract()) { currentOverTime = currentOverTime + Time.deltaTime; // Modifico visualizzazione Target TargetUI.color = Color.red; TargetUI.rectTransform.localScale = new Vector3(2.0f, 2.0f, 1.0f); // Modifico visualizzazione Counter CounterUI.fillAmount = currentOverTime / OverTimeLimit; CounterUI.rectTransform.localScale = new Vector3(3.0f, 3.0f, 3.0f); if (currentOverTime >= OverTimeLimit && alreadyClicked == false) { OnClick(hit); //currentOverTime = 0; alreadyClicked = true; } } else { ResetCounter(); } } else { ResetCounter(); } }
void OnClick(RaycastHit _hit) { Debug.Log("OnClick " + _hit.transform.name); InteractForAnimation componentFinded = _hit.transform.GetComponent <InteractForAnimation>(); if (componentFinded != null) { componentFinded.InteractionToggle(); } }