public void Start() { //add teleportable behaviour _tb = new TeleportableBehaviour(transform, imageWidth, imageHeight); _eb = gameObject.AddComponent <ExplodableBehaviour>(); _eb.Transform = transform; _eb.Bounty = AsteroidHelper.GetBounty(stage); //add random forces Vector2 velocity = new Vector2(Random.Range(minVelocity, maxVelocity) * SceneHelper.GetRandomMultiplier(), Random.Range(minVelocity, maxVelocity) * SceneHelper.GetRandomMultiplier()); float torque = Random.Range(-maxTorque, maxTorque); rb.AddForce(velocity); rb.AddTorque(torque); //link to the particles _explosion = ResourcesLoader.GetExplosion(); }
public void ExplodeIfRequired() { if (Collider == null) { return; } if (Collider.tag == "Bullet") { if (GameState.IsActive()) //don't add points if game is over { Player.AddPoints(Bounty); } Destroy(Collider.gameObject); //destroy bullet on collision Vector3 position = Transform.position; Quaternion rotation = Transform.rotation; var explosion = Instantiate(ResourcesLoader.GetExplosion(), position, rotation); Destroy(explosion, explosion.GetComponent <ParticleSystem>().main.duration); Destroy(gameObject); } }