类似于下面的C#代码: public float Choose(float[] probs) { float total = 0.0f; foreach (var elem in probs) { total = elem; } float randomPoint = Random.value * total; for (int i = 0; i < probs.Length; i ) { if (randomPoint <= probs[i]) return i; else randomPoint -= ...
class in UnityEngine 説明 ランダムなデータを生成するためのクラスです。 Static 変数 insideUnitCircle半径 1 の円の内部のランダムな点を返します(読み取り専用) insideUnitSphere半径 1 の球体の内部のランダムな点を返します(読み取り専用) ...
float Choose (float[] probs) { float total = 0; foreach (float elem in probs) { total += elem; } float randomPoint = Random.value * total; for (int i= 0; i < probs.Length; i++) { if (randomPoint < probs[i]) { return i; } else { randomPoint -= probs[i]; } }...
二、在不同概率下发生事件的场景: 一般将事件发生概率储存在一个数组中,比如float[]{0.5,0.25,0.2,0.05},此时随机生成一个介于0~1之间的数,与上述的值进行比较,很明显,这个随机数的值在0-0.5这个区间的概率最大。 float Choose (float[] probs) { float total = 0; foreach (float elem in probs) {...
publicfloatChoose(float[] probs) {floattotal =0.0f;foreach(vareleminprobs) { total+=elem; }floatrandomPoint = Random.value *total;for(inti =0; i < probs.Length; i++) {if(randomPoint <= probs[i])returni;elserandomPoint -=probs[i]; ...
intChoose(float[]probs){floattotal=0;foreach(floateleminprobs){total+=elem;}floatrandomPoint=Random.value*total;for(inti=0;i<probs.Length;i++){if(randomPoint<probs[i]){returni;}else{randomPoint-=probs[i];}}returnprobs.Length-1;} ...
public float Choose(float[] probs) { float total = 0.0f; foreach (var elem in probs) { total += elem; } float randomPoint = Random.value * total; for (int i = 0; i < probs.Length; i++) { if (randomPoint <= probs[i]) return i; ...
public void LevelUpInMatch() { switch (UnityEngine.Random.Range(0, 3)) { case 0: if (this.atk != CardPool.GetMaxStatCard((Int32)this.id).atk) { this.atk = (Byte)(this.atk + 1); } break; case 1: if (this.pdef != CardPool.GetMaxStatCard((Int32)this.id).pdef) { this.pd...
using System.Collections;using System.Collections.Generic;using UnityEngine;public class RandomNumberGenerator:MonoBehaviour{public GameObject gameObject;floatxOffset=0.0f;voidOnGUI(){xOffset=Random.Range(-5.0f,5.0f);if(GUI.Button(newRect(10,300,100,50),"MOVE")){gameObject.transform.position=newVecto...
最好的方法是使用您喜欢的生成器生成一个1到17之间的整数n,然后使用