// Create a mirrored asteroid for the screen edge border looping private GameObject InstantiateMirrorAsteroid(Vector3 _offset) { GameObject newAsteroid = Instantiate(GetAsteroidTypeFromTag(this.tag)); AsteroidController ac = newAsteroid.GetComponent <AsteroidController>(); ac.hasBeenInside = false; ac.isMirror = true; ac.InitMovement(this); // so it copies the movement and rotation of the original ac.parentAsteroid = this.gameObject; // move the mirror to _offset away so it appears as if it is the cut-off part of the original newAsteroid.transform.position = new Vector3(this.transform.position.x + _offset.x, this.transform.position.y + _offset.y, 0); newAsteroid.transform.parent = gameController.asteroidMirrorHolder.transform; return(newAsteroid); }
// This creates a new asteroid when the current one has been broken down // Adds random force, rotation, etc. private void CreateNewAsteroid(GameObject _asteroidObject) { GameObject newAsteroid = Instantiate(_asteroidObject); AsteroidController ac = newAsteroid.GetComponent <AsteroidController>(); ac.InitMovement(this); ac.hasBeenInside = true; Rigidbody2D acRB = newAsteroid.GetComponent <Rigidbody2D>(); acRB.velocity *= Random.Range(0.8f, 1.6f); Vector2 sideForce = Vector3.Cross(rb.velocity, Vector3.forward); acRB.AddForce(sideForce * (Random.Range(0, 100) >= 50 ? 1 : -1) * Random.Range(40.0f, 60.0f)); acRB.rotation = Random.Range(0, 360); acRB.angularVelocity = Random.Range(-90, 90); newAsteroid.transform.parent = this.transform.parent; }