I have a script that has a 5 percent chance to execute a function:
IEnumerator Example()
{
if (true)
{
if (Random.value > 0.95) //5% chance
{
yield return new WaitForSeconds(0.5f);
Debug.Log("yep");
gameObject.GetComponent<script>().enabled = true;
}
else
{
Debug.Log("nope");
}
}
}
What this does, is that it has a 5% chance to execute a certain piece of code, and then if true, enables script B. (It also keeps track of if it was executed. (through the debugs.))
And then in script B, I just have a simple debug saying if it was executed (I use OnEnable.)
On paper, it would be that the script B is executed the same number of times as Debug.Log(“yep”);
is, and there would be more “nopes” than yeps. Before, this was completely off, for example, 5 “yeps”
124 “nopes” and 116 of script Bs Debug.Log. And now, after changing nothing, it only produces script Bs Debug.Log. (note script B is turned off at the start through the inspector)
I am very confused and don’t know what to do, any help would be greatly appreciated, thanks.