都可以改变外部变量的值 void jiafa(int a, int b, ref int c) { c = a + b; } // Start is called before the first frame update void Start() { //ref修饰的必须在外面赋值 int res=0; jiafa(1, 2,ref res); print(res); } void jiafa(int a, int b, out int c) { c = a + b; } // Start is called before the first frame update void Start() { //out修饰的不用在外面赋值 int res; jiafa(1, 2, out res); print(res); }
常见泛型约束如下1.值类型 where 泛型字母:struct 2.引用类型 where 泛型字母:class 必须是引用类型 3.存在无参公共构造函数 where 泛型字母:new() 4.某个类本身或者其派生类 where 泛型字母:类名 5.某个接口的派生类型 where 泛型字母:接口名 6.另一个泛型类型本身或者派生类型 where 泛型字母:另一个泛型字母
using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.Events;public class weituoevent : MonoBehaviour{public UnityEvent myevent1; public UnityEvent<int> myevent2; public void dowork1() { print("无参事件"); } public void dowork2(int a) { print("有参事件" + a); } // Start is called before the first frame update void Start() { myevent1.AddListener(dowork1); //添加监听 myevent1?.Invoke(); //有就调用 myevent2.AddListener(dow
using UnityEngine;using UnityEngine.Events;public class random : MonoBehaviour{//声明带参委托 public UnityAction<string> aaa; //声明带参带返回值委托 public System.Func<int, int, int> bbb; public void Attack(string bossname) { print("打击怪兽:" + bossname); } public int addfunc(int a, int b) { return a + b; } public int addfunc2(int a, int b) { return a + b; } // Start is called before the first frame update void Start() { aaa=Attack; aaa("怪兽"); bbb = addfun
/Unity的随机数,int左包含,右不包含 //1-99 int a = Random.Range(1, 100); print(a); //float重载 左右都包含 float b = Random.Range(1, 99.5f); print(b);
一棵小松林
Gamer游戏开发者