45%的概率友好致敬
25%的概率转身离开
20%的概率攻击
10%的概率送礼
int choose()
{
float[] propArray = {45%,25%,20%,10%}
float total = 0.0f;
for(int i = 0 ; i < propArray.length;i++)
{
total += propArray[i];
}
float propValue = Random.value*total;
for(int i = 0 ; i< propArray.length; i++)
{
if(propValue < propArray[i])
{
return i;
}else{
propValue -= propArray[i];
}
}
return propArray.length - 1;
}
时间: 2024-10-10 22:58:17