public void SetStats(AsteroidValues stats) { base.angle = base.speed * 10 * (Random.Range(stats.minMaxRotation.x, stats.minMaxRotation.y) < 50 ? 1 : -1); base.health = stats.maxHealth; int maxPossibleAsteroidLvl = 0; if (stats.maxLevelOfAsteroid > stats.AsteroidSpriteList.Count - 1) { maxPossibleAsteroidLvl = stats.maxLevelOfAsteroid; } else { maxPossibleAsteroidLvl = stats.AsteroidSpriteList.Count - 1; } if (asteroidLevel > maxPossibleAsteroidLvl) { asteroidLevel = maxPossibleAsteroidLvl; } /* * List<int> sameLvlAsteroid = new List<int>(); * for (int i = 0; i < stats.AsteroidLvlGrouping.Count; i++) * { * if (stats.AsteroidLvlGrouping[i] == asteroidLevel) * sameLvlAsteroid.Add(i); * } * int choosenAsteroid = sameLvlAsteroid[(int)Random.Range(0, sameLvlAsteroid.Count - 1)]; * Debug.Log(choosenAsteroid); * base.sprite = stats.AsteroidSpriteList[choosenAsteroid]; * gameObject.GetComponent<CircleCollider2D>().radius = stats.AsteroidRadiusList[choosenAsteroid]; */ base.sprite = stats.AsteroidSpriteList[asteroidLevel]; gameObject.GetComponent <CircleCollider2D>().radius = stats.AsteroidRadiusList[asteroidLevel]; objectsCreator = new ObjectsCreator.ResourcesObjectsCreator(stats.baseAsteroidID); }
private void OnTriggerEnter(Collider other) { if (other.CompareTag("Boundary") || other.CompareTag("Enemy")) { return; } if (CompareTag("Asteroid") && other.CompareTag("Player")) { asteroidValues = GameObject.Find(name).GetComponent <AsteroidValues>(); asteroidValues.DamageTaken(5); Debug.Log(asteroidValues.GetAsteroidLife()); if (asteroidValues.GetAsteroidLife() <= 0f) { Instantiate(asteroids.asteroidExplosion, transform.position, transform.rotation); Destroy(gameObject); } playerController.DamageTaken(asteroidValues.asteroidDamage); if (gameController.GetPlayerLife() == 0f) { Instantiate(playerValues.playerExplosion, other.transform.position, other.transform.rotation); Destroy(other.gameObject); } } if (CompareTag("Enemy") && other.CompareTag("Player")) { Instantiate(enemies.enemyExplosion, transform.position, transform.rotation); Destroy(gameObject); playerController.DamageTaken(enemies.enemyHitDamage); if (gameController.GetPlayerLife() == 0f) { Instantiate(playerValues.playerExplosion, other.transform.position, other.transform.rotation); Destroy(other.gameObject); } } if (CompareTag("EnemyShot") && other.CompareTag("Player")) { playerController.DamageTaken(enemies.enemyShotDamage); Destroy(gameObject); if (gameController.GetPlayerLife() == 0f) { Instantiate(playerValues.playerExplosion, other.transform.position, other.transform.rotation); Destroy(other.gameObject); } } if (CompareTag("Asteroid") && other.CompareTag("PlayerShot")) { Instantiate(asteroids.asteroidExplosion, transform.position, transform.rotation); Destroy(other.gameObject); Destroy(gameObject); gameController.AddScore(scoreValue); gameController.DecreaseHazardCount(); //asteroid count? } if (CompareTag("Enemy") && other.CompareTag("PlayerShot")) { Instantiate(enemies.enemyExplosion, transform.position, transform.rotation); Destroy(other.gameObject); Destroy(gameObject); gameController.AddScore(scoreValue); //gameController.DecreaseHazardCount(); //TODO enemy count? } if (CompareTag("Enemy") && other.CompareTag("Asteroid")) { Instantiate(enemies.enemyExplosion, transform.position, transform.rotation); Instantiate(asteroids.asteroidExplosion, other.transform.position, other.transform.rotation); Destroy(other.gameObject); Destroy(gameObject); //enemy.damagetaken? } }