void InstanciateAsteroid() { Vector3 asteroidScale = (Vector3.one + Random.insideUnitSphere * 0.1f) * Random.Range(minScaleSize, maxScaleSize); Vector3 asteroidPosition = ToVector3(Random.insideUnitCircle * 2f * zoneRadius); float asteroidRadius = asteroidScale.magnitude; int tryCount = 10; while (Physics.CheckSphere(asteroidPosition, asteroidRadius, checkLayerMask) && tryCount > 0) { asteroidPosition = ToVector3(Random.insideUnitCircle * 2f * zoneRadius); tryCount--; } if (tryCount == 0) { //Fail to find a good position for the new asteroid //Debug.LogWarning("Fail to find a good position for the new asteroid"); return; } GameObject go = Instantiate(asteroidPrefabs[Random.Range(0, asteroidPrefabs.Length)], asteroidPosition, Random.rotation) as GameObject; go.transform.localScale = asteroidScale; AsteroidProp a = go.GetComponent <AsteroidProp>(); a.health = 10; a.split = 2; Rigidbody r = go.GetComponent <Rigidbody>(); r.velocity = ToVector3(Random.insideUnitCircle.normalized * Random.Range(minVelocity, maxVelocity)); r.angularVelocity = Random.insideUnitSphere * initialAngularVelocity; }
void OnTriggerEnter(Collider other) { if (other.tag == "Asteroid") { AsteroidProp ap = other.GetComponent <AsteroidProp>(); ap.TakeHealthDamage(10000000f, currentShooter.gameObject); currentShooter.Score += ap.scorePoint; } else if (other.tag == "Player") { PlayerBase pb = other.GetComponent <PlayerBase>(); pb.TakeHealthDamage(damage, currentShooter.gameObject); currentShooter.Score += Mathf.RoundToInt(pb.Score * 0.2f); } //CancelInvoke("AutoDestroy"); AutoDestroy(); }