示例#1
0
    private bool attackWhilePlayerIsgrounded = true; //only attack when the player is on the ground, and not while he's jumping

    public void ATTACK()
    {
        if (target == null)
        {
            SetTarget2Player();
        }

        if (Time.time - lastAttackTime > attackInterval)
        {
            //checks if we should only attack when the player is grounded
            if (attackWhilePlayerIsgrounded)
            {
                if (target.GetComponent <PlayerMovement>().playerIsGrounded())
                {
                    enemyState = ENEMYSTATE.ATTACK;
                    Move(Vector3.zero, 0);                     //when commented the character runs to the other side
                    LookAtTarget();
                    animator.Attack1();
                    lastAttackTime = Time.time;
                }
            }
            else
            {
                enemyState = ENEMYSTATE.ATTACK;
                Move(Vector3.zero, 0);                         //when commented the character runs to the other side
                LookAtTarget();
                animator.Attack1();
                lastAttackTime = Time.time;
            }
        }
    }
        void DoTheMethod()
        {
            var go = Fsm.GetOwnerDefaultTarget(gameObject);

            if (go == null)
            {
                return;
            }

            theScript.Attack1();
        }