示例
所有人看到同一件随机战利品,而且一条网络消息都不用发:大家用同一个种子做同样的计算。
using UnityEngine;
using Cilbox;
[Cilboxable]
public class RandomLoot : MonoBehaviour
{
public GameObject[] options;
public int seed = 12345;
void Start()
{
if (options == null || options.Length == 0) return;
int value = seed;
value = value * 1103515245 + 12345;
int index = value % options.Length;
if (index < 0) index = -index;
for (int i = 0; i < options.Length; i++) options[i].SetActive(i == index);
}
}