Exemplo n.º 1
0
 void OnTriggerStay2D(Collider2D collider)
 {
     if (collider.tag == "Player")
     {
         if (MainScript.Player.FuelLevel < 100)
         {
             MainScript.Player.FuelLevel += refuelingSpeed;
             if (!restSound.isPlaying && !startSound.isPlaying)
             {
                 restSound.Play();
             }
         }
         if (MainScript.Player.FuelLevel > 100)
         {
             if (!restSound.isPlaying)
             {
                 restSound.pitch = 1.08f;
                 restSound.Play();
             }
         }
     }
     if ((collider.tag == "Missile"))
     {
         FuelTank fuelTank = MainScript.fuelTanks.Find(x => x.GameObject.Equals(gameObject));
         Missile  missile  = MainScript.missiles.Find(x => x.GameObject.Equals(collider.gameObject));
         MainScript.Player.Points += score;
         GameObject smallExplosion = GameObject.Instantiate(Resources.Load("Prefabs/SmallExplosionPrefab", typeof(GameObject))) as GameObject;
         smallExplosion.transform.position = new Vector2(fuelTank.GameObject.transform.position.x, fuelTank.GameObject.transform.position.y);
         Destroy(smallExplosion, 1);
         Destroy(fuelTank.GameObject);
         MainScript.fuelTanks.Remove(fuelTank);
         MissileScript.CheckTypeOfMissile(ref missile);
     }
 }
Exemplo n.º 2
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        if ((collider.tag == "Terrain" || collider.tag == "Finish") && gameObject.name != "SpacePlanePrefab(Clone)")
        {
            int rotation   = 180;
            var enemySpeed = MainScript.enemies.Find(x => x.GameObject.Equals(gameObject)).Speed *= -1;
            gameObject.GetComponent <Rigidbody2D>().velocity = new Vector2(enemySpeed * MainScript.Player.DefaultSpeed, 0);
            if (enemySpeed < 0 && gameObject.name == "TankPrefab(Clone)")
            {
                rotation += rotation;
            }
            if (enemySpeed > 0 && gameObject.name == "RedEnemyPrefab(Clone)")
            {
                rotation += rotation;
            }
            if (enemySpeed > 0 && gameObject.name == "RedEnemyPrefab(Clone)")
            {
                rotation += rotation;
            }
            gameObject.transform.localRotation = Quaternion.Euler(0, rotation, 0);
        }

        if (collider.tag == "Missile" || collider.tag == "Player")
        {
            Enemy enemy = MainScript.enemies.Find(x => x.GameObject.Equals(gameObject));
            if (collider.tag == "Player")
            {
                if (MainScript.Player.CurrentHealth >= 1)
                {
                    playerHit.GetComponent <AudioSource>().Play();
                }
                enemy.Health = 0f;
            }
            else
            {
                Missile missile;
                missile = MainScript.missiles.Find(x => x.GameObject.GetComponent <Collider2D>().Equals(collider));
                float damage = missile.Damage;
                enemy.Health -= damage;
                MissileScript.CheckTypeOfMissile(ref missile);
                whiteSprite();
                isWhite = true;
            }
            if (enemy.Health <= 0)
            {
                MainScript.KillEnemy(enemy);
            }
        }
    }