Example #1
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.tag == "JumpTrigger" && enemyType == EnemyType.Jumping)
     {
         GameObject blob = GameObject.FindGameObjectWithTag("Blob");
         if (blob != null)
         {
             float blobY = Mathf.Round(blob.GetComponent <BlobMovement>().chaseY *2) / 2;
             float myY   = Mathf.Round(transform.position.y * 2) / 2;
             if (myY < blobY)
             {
                 JumpTrigger.DirectionLimit dir = other.GetComponent <JumpTrigger>().directionLimit;
                 if (dir == JumpTrigger.DirectionLimit.None || (dir == JumpTrigger.DirectionLimit.Left && _faceDir == -1) || (dir == JumpTrigger.DirectionLimit.Right && _faceDir == 1))
                 {
                     Jump();
                 }
             }
         }
     }
 }
Example #2
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag == "JumpTrigger")
        {
            JumpTrigger.DirectionLimit dir = other.GetComponent <JumpTrigger>().directionLimit;
            if (dir == JumpTrigger.DirectionLimit.None || (dir == JumpTrigger.DirectionLimit.Left && _faceDir == -1) || (dir == JumpTrigger.DirectionLimit.Right && _faceDir == 1))
            {
                if ((food != null && food.transform.position.y > transform.position.y) || other.GetComponent <JumpTrigger>().alwaysJump)
                {
                    Jump();
                }
            }
        }
        if (other.gameObject.tag == "Food")
        {
            Destroy(other.gameObject);
            StartCoroutine("Eat", true);
        }
        if (other.gameObject.tag == "Enemy")
        {
            if (!canDie)
            {
                ++enemiesEaten;
                //Play eatign sound ~Adam
                mPetSounds.PlayOneShot(mPetEatingSound);
                if (other.GetComponent <EnemyMovement>() != null)
                {
                    other.GetComponent <EnemyMovement>().SpawnDeathEffect();
                }
                if (other.GetComponent <BouncingEnemy>() != null)
                {
                    other.GetComponent <BouncingEnemy>().SpawnDeathEffect();
                }

                gameController.AddScre(1);
                uiController.IncreaseEvolution();
                //Play a sound for the enmey death ~Adam
                if (other.GetComponent <EnemyMovement>() != null)
                {
                    mEnemyDeathSounds.PlayOneShot(other.GetComponent <EnemyMovement>().mEnemyDeathSound);
                }
                if (other.GetComponent <BouncingEnemy>() != null)
                {
                    mEnemyDeathSounds.PlayOneShot(other.GetComponent <BouncingEnemy>().mEnemyDeathSound);
                }
                Destroy(other.gameObject);

                StartCoroutine("Eat", false);
            }
            else
            {
                if (evolveLevel == 0)
                {
                    if (!evolveCooldown)
                    {
                        other.GetComponent <AudioSource>().PlayOneShot(mPetDeathSound);
                        Destroy(playerAnimation.gameObject);
                        gameController.GameOver();
                        if (deathEffect != null)
                        {
                            Instantiate(deathEffect, transform.position, Quaternion.identity);
                        }
                        Destroy(gameObject);
                    }
                }
                else
                {
                    --evolveLevel;
                    uiController.ResetEvolution();
                    mPetSounds.PlayOneShot(mPetGotHitSound);
                    StartCoroutine("Evolve");
                }
            }
        }

        if (other.gameObject.tag == "Player")
        {
            isRunning = false;
        }
    }