// Update is called once per frame void Update() { float dist = distance; Ray raycast = new Ray(transform.position, transform.forward); RaycastHit hit; bool bHit = Physics.Raycast(raycast, out hit); if (bHit && hit.distance < distance) { dist = hit.distance; if (prevGO != null && prevGO != hit.transform.gameObject) { if (prevGO.GetComponent <PointableObject>() != null) { prevGO.GetComponent <PointableObject>().PointerExit(); } } currContact = hit.transform.gameObject.GetComponent <PointableObject>(); if (currContact != null) { isActive = true; SetPointerColor(isActive); currContact.PointerEnter(); } prevGO = hit.transform.gameObject; } else { if (isActive) { isActive = false; SetPointerColor(isActive); } if (currContact != null) { currContact.PointerExit(); currContact = null; } } if ((currContact != null) && OVRInput.GetDown(OVRInput.RawButton.RIndexTrigger)) { currContact.PointerClick(); } if (OVRInput.Get(OVRInput.RawButton.RIndexTrigger)) { pointer.transform.localScale = new Vector3(thickness * 5f, thickness * 5f, dist); } else { pointer.transform.localScale = new Vector3(thickness, thickness, dist); } pointer.transform.localPosition = new Vector3(0f, 0f, dist / 2f); }
/* * HandlePointerOut: Called whenever the user clicks on a gameobject with a PointableObject script * Parameters: object sender - contains method info * PointerClickedEventArgsEventArgs e - contains the hit information such as the gameobject being collided with */ private void HandlePointerClick(object sender, ClickedEventArgs e) { targetObject.PointerClick(); }