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

Unity中的随机数

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

cs 复制代码
int randoNum = Random.Range(0, 100);
float randoNumF = Random.Range(1.1f, 99.9f);

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

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

cs 复制代码
Random rd = new Random();

int i = rd.Next();

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

Unity的自带委托

c#中的委托

cs 复制代码
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;

cs 复制代码
UnityAction uac = () =>
{

};
UnityAction<string> uac2 = (str) =>
{
};
相关推荐
DaLiangChen10 小时前
Vuforia 地面识别案例
unity·ar
江畔柳前堤17 小时前
YOLO 目标检测全流程深度剖析
人工智能·yolo·目标检测·计算机视觉·unity·面试·vllm
魔术师Dix19 小时前
一个轮子:Luban Skill 制作演示
游戏·unity·ai编程
xcLeigh1 天前
Unity基础:Light灯光组件入门——Directional Light、Point Light与Spotlight
unity·游戏引擎·教程
郝学胜-神的一滴2 天前
[简化版 GAMES 104] 现代游戏引擎 04:从0到1构建你的游戏世界
c++·游戏·unity·游戏引擎·软件工程·unreal engine
是嘟嘟啊3 天前
【Unity DOTS】EntityCommandBuffer 与 JobHandle
unity·ecs·dots·unity dots·job·burst·burstjob
xcLeigh3 天前
Unity基础:Camera相机组件详解——透视投影与正交投影的区别
数码相机·unity·游戏引擎
玖玥拾3 天前
Unity3D RPG 入门项目(二)移动 Bug 修复、环绕相机、NPC 任务系统、UI 穿透处理
unity·游戏引擎
Yasin Chen3 天前
Unity UGUI RectMask2D 原理
unity·游戏引擎
hashiqimiya3 天前
unity---unity编译手机apk人物角色移动
unity·游戏引擎