Ejemplo n.º 1
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);
            }
        }
    }