public void destroyAsteroid() { ship.changeScore(score); Size newSize = Size.Small; if (size == Size.Large) { newSize = Size.Medium; } else if (size == Size.Medium) { newSize = Size.Small; } else if (size == Size.Small) { PickupController.spawnPickup(this.level, this.transform.position); parent.changeAsteroidCount(-1); Destroy(this.gameObject); return; } GameObject newAsteroid1 = Instantiate(asteroidPrefab, new Vector3(this.transform.position.x + (transform.localScale.x), this.transform.position.y + (transform.localScale.y), 0), Quaternion.identity); GameObject newAsteroid2 = Instantiate(asteroidPrefab, new Vector3(this.transform.position.x - (transform.localScale.x), this.transform.position.y - (transform.localScale.y), 0), Quaternion.identity); Vector2 newDirection = new Vector2(Random.Range(-8 - level, 8 + level), Random.Range(-8 - level, 8 + level)); newAsteroid1.GetComponent <AsteroidController>().setValues(this.baseHealth / 2, newDirection, newSize, parent); newAsteroid2.GetComponent <AsteroidController>().setValues(this.baseHealth / 2, -newDirection, newSize, parent); parent.changeAsteroidCount(-1); Destroy(this.gameObject); }
public void setValues(float health, Vector2 direction, Size size, AsteroidSpawner parent) { this.parent = parent; parent.changeAsteroidCount(1); this.health = health; this.baseHealth = health; this.maxDamage = this.maxDamage - ((2 - (int)size) * 0.25f) * this.maxDamage; this.score = (int)(this.score - ((2 - (int)size) * 0.25f) * this.score); this.direction = direction; this.rb.velocity = direction; this.size = size; if (size == Size.Large) { this.rb.mass = 8f; this.transform.localScale = new Vector3(1f, 1f, 1f); } else if (size == Size.Medium) { this.rb.mass = 4f; this.transform.localScale = new Vector3(0.65f, 0.65f, 0.65f); } else if (size == Size.Small) { this.rb.mass = 2f; this.transform.localScale = new Vector3(0.35f, 0.35f, 0.35f); } //this.rb.angularVelocity = Random.Range(-3.8f* (2 - (int)size), 3.8f * (2 - (int)size)); }
public void setParent(AsteroidSpawner parent) { this.parent = parent; parent.changeAsteroidCount(1); }