Пример #1
0
    void GetInteraction()
    {
        Ray        interactionRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit interactionInfo;

        if (Physics.Raycast(interactionRay, out interactionInfo, Mathf.Infinity))
        {
            playerAgent.updateRotation = true;
            GameObject interactedObject = interactionInfo.collider.gameObject;
            if (interactedObject.tag == "Enemy")
            {
                CancelLastInteractable(interactedObject.GetComponent <Interactable>());
                playerWeaponController.OnTargetInteraction(playerAgent);
                interactedObject.GetComponent <Interactable>().MoveToInteraction(playerAgent);
                MusicHandler.PlayWarMusic();
            }
            else if (interactedObject.tag == "Interactable Object")
            {
                CancelLastInteractable(interactedObject.GetComponent <Interactable>());
                playerAgent.stoppingDistance = 2f;
                interactedObject.GetComponent <Interactable> ().MoveToInteraction(playerAgent);
            }
            else
            {
                CancelLastInteractable();
                playerAgent.stoppingDistance = 0;
                playerAgent.destination      = interactionInfo.point;
            }
        }
    }
Пример #2
0
    void FixedUpdate()
    {
        Collider[] withinAggroColliders = Physics.OverlapSphere(transform.position, 10, aggroLayerMask);
        if (withinAggroColliders.Length > 0)
        {
            CancelInvoke("BackToInitialPosition");
            CancelInvoke("Heal");
            Collider collider = withinAggroColliders[0];
            MusicHandler.PlayWarMusic();

            ChasePlayer(collider.GetComponent <Player>());
        }
        else if (navMeshAgent.velocity.Equals(Vector3.zero) && Vector3.Distance(transform.position, initialPosition) > navMeshAgent.stoppingDistance)
        {
            if (!IsInvoking("BackToInitialPosition"))
            {
                Invoke("BackToInitialPosition", 5.0f);
            }
        }
        else if (Vector3.Distance(transform.position, initialPosition) <= navMeshAgent.stoppingDistance)
        {
            if (IsInvoking("BackToInitialPosition"))
            {
                CancelInvoke("BackToInitialPosition");
            }
        }
    }