Exemple #1
0
    //RAYCAST OBJECTS___________________________________________________________________________________

    public GameObject RaycastObject(bool interactOnly)
    {
        bool       isResult      = false;
        GameObject raycastObject = null;
        Vector3    testPosition  = GetFrontPosition();

        Collider[] hitColliders = Physics.OverlapSphere(testPosition, reglages.raycastRadius);
        int        i            = 0;

        while (i < hitColliders.Length)
        {
            if (!interactOnly)
            {
                if (CanInteract(hitColliders[i].gameObject))
                {
                    isResult = true;
                    if (interactObject != null)
                    {
                        interactObject.GetComponent <InteractObject>().UpdateFeedback(false);
                    }
                    interactObject = hitColliders[i].gameObject;
                    interactObject.GetComponent <InteractObject>().UpdateFeedback(true);
                    i = hitColliders.Length;
                    soundManager.PlayInteractFeedbackSound(interactObject);
                }
            }
            else
            {
                if (IsInteractionWhileCarying(hitColliders[i].gameObject))
                {
                    isResult = true;
                    if (interactObject != null)
                    {
                        interactObject.GetComponent <InteractObject>().UpdateFeedback(false);
                    }
                    interactObject = hitColliders[i].gameObject;
                    interactObject.GetComponent <InteractObject>().UpdateFeedback(true);
                    i = hitColliders.Length;
                    soundManager.PlayInteractFeedbackSound(interactObject);
                }
            }
            i++;
        }
        if (!isResult)
        {
            if (interactObject != null)
            {
                interactObject.GetComponent <InteractObject>().UpdateFeedback(false);
            }
            interactObject = null;
            soundManager.ResetInteractObject();
        }
        return(raycastObject);
    }