三亩地 三亩地SAN MU DI · CODE DIARY
ARTICLE DETAIL

日记详情

真实记录编程学习的某一天,欢迎挑你感兴趣的翻一翻。

Unity(十七)Unity随机数及Unity委托

Unity(十七)Unity随机数及Unity委托

Unity中的随机数

Unity中的Random是Unity中特有的,与C#的不一样

int randoNum = Random.Range(0, 100); float randoNumF = Random.Range(1.1f, 99.9f);

使用随机数 int 重载 规则是左包含,右不包含

使用浮点数重载,规则是左右都包含

Random rd = new Random(); int i = rd.Next();

c#中的Random随机数是左包含右不包含

Unity的自带委托

c#中的委托

System.Action ac = () => { print("123"); }; System.Action<int, float> ac2 = (i, f) => { }; System.Func<int> fun1 = () => { return 1; }; System.Func<int, string> fun2 = (i) => { return "123"; };

Unity中的委托

要引用using UnityEngine.Events;

UnityAction uac = () => { }; UnityAction<string> uac2 = (str) => { };
← 返回列表