In my OnTrigger function when the player collides with Mystery Pickup it should randomly pick a number for ‘i’ to call a weapon for my star ship sort of like mario kart. It keeps picking 6 and shooting a nuke everytime. Any ideas on what I’m doing wrong? Thanks.
edit: here’s the working code.
if(other.gameObject.tag ==("MysteryPickup"))
{
int numOptions = 7;
int arrayLength = numOptions;
for(float i = 0; i < arrayLength; i++){
float prob = 1f / numOptions;
if(Random.value <= prob){
//do whatever i is
if(i == 6) //nuke
{
shootScriptB.nukeOn = true;
Destroy(other.gameObject);
}
if(i == 5) //shield
{
shieldOn = true;
}
if(i == 4) //speed boost
{
speed = 6;
speedBoostOn = true;
Destroy(other.gameObject);
jet1.SetActive(true);
jet2.SetActive(true);
StartCoroutine(SpeedBoostTime() );
}
if(i == 3) //double missiles
{
shootScriptB.doubleMissileOn =false;
shootScriptB.missileON = true;
Destroy(other.gameObject);
}
if(i == 2) // missile
{
shootScriptB.doubleMissileOn =false;
shootScriptB.missileON = true;
Destroy(other.gameObject);
}
if(i == 1) //double lazers
{
shootScript.doubleLazerOn =true;
shootScript.lazerON =false;
Destroy(other.gameObject);
}
Debug.Log(i);
break;
}
numOptions--;
}
Destroy(other.gameObject);
}
}