Esempio n. 1
0
    private void Update()
    {
        if (m_ActiveAction == null)
        {
            return;
        }
        m_ActiveAction.PerformAction();

        if (m_ActiveAction.Action == EnemyAction.Actions.EnemyMoveToPlayer)
        {
            m_DetectionTimer -= Time.deltaTime;
            if (m_DetectionTimer < 0)
            {
                m_DetectionTimer = m_DetectionTimerDefault;
                if (!m_EnemyPlayerDetection.CanPlayerBeSeen())
                {
                    m_EnemyMoveToPlayer.StopEnemy();
                    SetActiveAction(EnemyAction.Actions.EnemyPlayerDetection);
                }
            }

            if (m_CollisionBox.IsTouchingLayers(m_WhatIsTarget))
            {
                SetActiveAction(EnemyAction.Actions.EnemyMeleeAttack);
            }
        }
    }
Esempio n. 2
0
    void Update()
    {
        if (m_ActiveAction == null)
        {
            return;
        }
        m_ActiveAction.PerformAction();

        if (m_ActiveAction.Action == EnemyAction.Actions.EnemyRangedAttack)
        {
            if (!m_EnemyPlayerDetection.CanPlayerBeSeen())
            {
                SetActiveAction(EnemyAction.Actions.EnemyPatrol);
            }
        }
    }
Esempio n. 3
0
    void Update()
    {
        if (!m_EnemyMoveToPlayer)
        {
            Debug.LogError("No Enemy Move To Player Action script attached to " + gameObject.name);
        }
        if (!m_EnemyPlayerDetection)
        {
            Debug.LogError("No Enemy Player Detection script attached to " + gameObject.name);
        }
        if (!m_FrontCollider)
        {
            Debug.LogError("No Box Collider 2D attached to " + gameObject.name);
        }

        if (m_ActiveAction == null)
        {
            return;
        }
        m_ActiveAction.PerformAction();

        if (m_FrontCollider.IsTouchingLayers(m_AttackableLayers))
        {
            SetActiveAction(EnemyAction.Actions.EnemyMeleeAttack);
        }

        if (m_ActiveAction.Action == EnemyAction.Actions.EnemyMoveToPlayer)
        {
            m_DetectionTimer -= Time.deltaTime;
            if (m_DetectionTimer < 0)
            {
                m_DetectionTimer = m_DetectionTimerDefault;
                if (!m_EnemyPlayerDetection.CanPlayerBeSeen())
                {
                    m_EnemyMoveToPlayer.StopEnemy();
                    SetActiveAction(EnemyAction.Actions.EnemyPatrol);
                }
            }
        }
    }
Esempio n. 4
0
    /// <summary>
    /// Performs the patrol action.
    /// </summary>
    public override void PerformAction()
    {
        if (!m_IsWalking)
        {
            m_BasicEnemy.SetWalking(true);
            m_IsWalking = true;
            m_Animator.SetBool("IsWalking", true);
            if (m_WalkingDirection == 1 && !m_BasicEnemy.FacingRight)
            {
                m_BasicEnemy.Flip();
            }
            else if (m_WalkingDirection == -1 && m_BasicEnemy.FacingRight)
            {
                m_BasicEnemy.Flip();
            }
        }

        m_WalkAmount.x = m_WalkingDirection * m_WalkSpeed * Time.deltaTime;

        if (m_WallCheckCollider.IsTouchingLayers(m_WhatIsGround))
        {
            m_WalkingDirection = -m_WalkingDirection;
            m_BasicEnemy.Flip();
        }
        else if (!m_FloorCheckCollider.IsTouchingLayers(m_WhatIsGround))
        {
            m_WalkingDirection = -m_WalkingDirection;
            m_BasicEnemy.Flip();
        }

        m_EnemyAudio.PlayWalkAudioClip();
        m_BasicEnemy.transform.Translate(m_WalkAmount);

        if (m_EnemyPlayerDetection.CanPlayerBeSeen() && !m_PatrolCooldown)
        {
            m_PlayerDetected.Invoke();
            m_IsWalking = false;
        }
    }