Пример #1
0
    protected override void OnTriggerEnter2D(Collider2D other)
    {
        // Check if the tag of the trigger collided with is GoodTroop.
        if (other.tag == "GoodTroop" && opponent == null)
        {
            // Set opponent to equal the component passed in as a parameter.
            opponent = other.gameObject.GetComponent <GoodTroop>();


            // Set the attack trigger of the BadTroop's animation controller in
            // order to play the BadTroop's attack animation.
            animator.ResetTrigger("BadTroopWalk");
            animator.SetTrigger("BadTroopFight");

            // Set isFighting to true, indicates BadTroop is in fighting state
            isFighting = true;
        }
        else if (other.tag == "BadTroop" && opponent == null)
        {
            // If collided with another BadTroop, whichever BadTroop is
            // further forward (to the left) has priority to move, while the
            // one behind waits.
            if (other.gameObject.transform.position.x < transform.position.x)
            {
                isWaiting = true;
            }
        }
    }
Пример #2
0
    protected override void OnTriggerExit2D(Collider2D other)
    {
        // Set the walk trigger of the BadTroop's animation controller in
        // order to play the BadTroop's walking animation.
        animator.ResetTrigger("BadTroopWalk");
        animator.SetTrigger("BadTroopWalk");

        // Reset parameters
        isFighting = false;
        isWaiting  = false;
        opponent   = null;
    }