I am working with C# in Unity3D (2018.3.0f2) and I need to create a random function with multiple outcomes and multiple parameters. Is there any better way? Mine works, but I would like to have it in a list and if possible shorter.
float rndFloat = Random.value;
if (rndFloat < 0.33f) occlusionTime = 0.3f;
else if (rndFloat >= 0.33f && rndFloat < 0.66f) occlusionTime = 0.7f;
else occlusionTime = 1.1f;
rndFloat = Random.value;
if (rndFloat < 0.25f)
{
BallEnd.transform.position = EndPositions[0];
endPosPixelCoords = EndPositionsPixel[0];
}
if (rndFloat >= 0.25f && rndFloat < 0.5f)
{
BallEnd.transform.position = EndPositions[1];
endPosPixelCoords = EndPositionsPixel[1];
}
if (rndFloat >= 0.5f && rndFloat < 0.75f)
{
BallEnd.transform.position = EndPositions[2];
endPosPixelCoords = EndPositionsPixel[2];
}
if (rndFloat >= 0.75f)
{
BallEnd.transform.position = EndPositions[3];
endPosPixelCoords = EndPositionsPixel[3];
}
Aucun commentaire:
Enregistrer un commentaire