Пример #1
0
    protected virtual void LateUpdate()
    {
        var result = raycaster.FirstRaycastResult();

        if (!result.isValid || result.gameObject == null)
        {
            var scaledDistance = transform.InverseTransformVector(0f, 0f, raycaster.FarDistance).magnitude;
            rayScaler.localScale = new Vector3(1f, 1f, scaledDistance);
            if (reticle.gameObject.activeSelf)
            {
                reticle.gameObject.SetActive(false);
            }
        }
        else
        {
            var scaledDistance = transform.InverseTransformVector(0f, 0f, result.distance).magnitude;
            rayScaler.localScale = new Vector3(1f, 1f, scaledDistance);
            if (!reticle.gameObject.activeSelf)
            {
                reticle.gameObject.SetActive(true);
            }
            reticle.position = result.worldPosition;
            //Debug.Log(result.gameObject.name + "distance=" + result.distance);
        }
        hitTarget   = result.gameObject;
        hitDistance = result.distance;
    }
Пример #2
0
    private IEnumerator CastRays()
    {
        if (rightGuideLine == null || leftGuideLine == null)
        {
            UpdateViveRayCasters();
        }

        yield return(null);

        rightGuideLine.SetActive(true);
        leftGuideLine.SetActive(true);

        castingRays = true;

        while (castingRays)
        {
            if (rightRay != null || leftRay != null)
            {
                rightTarget = rightRay.FirstRaycastResult().gameObject;
                leftTarget  = leftRay.FirstRaycastResult().gameObject;
            }
            else
            {
                UpdateViveRayCasters();
            }

            yield return(null);
        }

        rightTarget = null;
        leftTarget  = null;
        rightGuideLine.SetActive(false);
        leftGuideLine.SetActive(false);
    }