(サンプルコード)オブジェクトの出現確率をコントロールする。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameManager : MonoBehaviour
{
public GameObject[] tankPrefab;
private int number;
void Start()
{
// 1から100までの中からランダムに数字を選択する。
number = Random.Range(1, 100);
// 選択した数字をコンソール画面に表示
print(number);
// 選択した数字が20以下ならばtankPrefab[0]に設定したタンクを出現させる。(出現率20%)
if (number <= 20)
{
Instantiate(tankPrefab[0], new Vector3(0, 1, -50), Quaternion.identity);
}
// 選択した数字が21〜100ならばtankPrefab[1]に設定したタンクを出現させる。(出現率80%)
else
{
Instantiate(tankPrefab[1], new Vector3(0, 1, -50), Quaternion.identity);
}
}
}