Random spawn

I have been working with the space shooter tutorial. I have been able to create a health and weapon prefab that spawn when an asteroid is destroyed. The problem is that they both spawn every single time an asteroid is destroyed. I would like them to spawn randomly. I would like the weapon pickup to spawn every 25 asteroids and the health pickup to spawn every 50 asteroids. I’m very new to unity and some guidance would be greatly appreciated.

Here is the current code I’m working with:

using UnityEngine;
using System.Collections;

public class DestroyByContact : MonoBehaviour 
{
	public GameObject explosion;
	public GameObject playerExplosion;
	public int scoreValue;
	private GameController gameController;

	public GameObject weapon;
	public GameObject health;

	void Start ()
	{
		GameObject gameControllerObject = GameObject.FindWithTag ("GameController");
		if (gameControllerObject != null)
		{
			gameController = gameControllerObject.GetComponent <GameController>();
		}
		if (gameController == null) {
			Debug.Log ("Cannot find 'GameController' script");
				}
	}

	void OnTriggerEnter(Collider other) {
		if (other.tag == "Boundary") {
			return;
				}

		if (other.tag == "Capsule") {
			return;
		}
		Instantiate (explosion, transform.position, transform.rotation);

		GameObject weaponClone = (GameObject) Instantiate(weapon, transform.position, transform.rotation);
		GameObject healthClone = (GameObject) Instantiate(health, transform.position, transform.rotation);

		if (other.tag == "Player") 
		{	
			Instantiate (playerExplosion, other.transform.position, other.transform.rotation);
			gameController.GameOver ();
		}
		gameController.AddScore (scoreValue);
		Destroy(other.gameObject);
		Destroy (gameObject);
	}
}

If you are talking about a percent chance drop then you can simply use Random

If you want it to drop every 25 asteroids destroyed then you could try the following.
One way is to have a script that can keep track of how many asteroids get destroyed. You can also have this over-seeing script(I’ll call it AsteroidManager from now on) handle the reward spawning if you wish. There are many ways to keep track of which objects get destroyed. Keep an int as a running total of the asteroids that get destroyed. Then for keeping track of asteroids getting destroyed here are a few options:

  1. Have the asteroid cache the AstroidManager script. Add to the running total via the asteroid just before destroying it.

  2. Keep an array or list of all the asteroids that you spawn. You could loop through your array/list of spawned asteroids and see if the exist or not. You could have this check occur only periodically if you like.

  3. Use a singleton. This makes things easy in this situation but use singletons sparingly and with caution. Basically, in your AstroidManager script, have a static int that you can add to Globally. This means you should only have 1 instance of the over-seeing script in your game. Then in your asteroid script you can just do AsteroidManager.asteroidsDestroyed++;

  4. Another way is to use GameObject.SendMessage. This can allow for decoupling between the astroid and AstroidManager. However, note that SendMessage has relatively large overhead so use it sparingly.

  5. Delegates and Events are an option. Similar to SendMessage. Trigger an asteroid destroyed event whenever an asteroid is destroyed. Any objects that have methods subscribed to that event will run(Like in AstroidManager for example). You can add to the running total everytime this event occurs.

There are more ways but I hope these options help.