NPC随机响应算法
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;
}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。