Example #1
0
    void OnCollisionEnter2D(Collision2D other)
    {
        // If your animal collides with an enemy
        if (other.gameObject.CompareTag("Enemy") && (Time.timeSinceLevelLoad - forceFollowTimer) > 1)
        {
            //Debug.Log("An animal has hit an enemy!");

            // Don't make the player go back to the player
            StopCoroutine(waitAndComeBack());
            StopAllCoroutines();

            isAttacking = true;
            if (isMoving == true)
            {
                caught = false;
                int        temp   = queueIndex;
                GameObject player = GameObject.Find("Player");

                player.GetComponent <Player>().removeFromQueue(this);
                queueIndex = player.GetComponent <Player>().getCurrentAnimalQueueSize();
                player.GetComponent <Player>().queueManagementExtras();
                player.GetComponent <Player>().updateQueuePositions(temp);
            }
            isMoving = false;

            if (targetContainer.GetTarget() == null)
            {
                Target myTemp1 = new Target(other.gameObject, targetContainer);
                other.gameObject.GetComponent <IEnemy>().selfAsTargets.Add(myTemp1);
                targetContainer.AddTarget(myTemp1);
            }

            //add set up the target container
            TargetContainer tc = other.gameObject.GetComponent <IEnemy>().targetContainer;

            Target myTemp = new Target(gameObject, tc);
            selfAsTargets.Add(myTemp);
            tc.AddTarget(myTemp);

            // TODO: Make the enemy stop moving (This was taken care of by me (Ian) if I understand correctly)
        }
    }