快捷键修改文件名是F12
类名和文件名要一致
ctrl+s保存场景、文件和代码
快捷键修改文件名是F12
类名和文件名要一致
ctrl+s保存场景、文件和代码
start是初始化,执行一次
void Start(){ Test(); Test(); } void Test(){ print("输出一个敌人1"); } Void CreatEnemy(){ print("创建敌人"); print("设置敌人位置"); print("设置敌人的初始属性"); }
int roleType = 0; RoleTyoe rt = RoleType.Mag; tt = roleType.Soldier;
enum
输出 print
组合快捷键 ctr+k,ctrl+c
变量
整数类型 int
浮点类型 float
单个字符 bool
字符串 string
只要有继承Monobehavior 就可以使用print
否则,就使用费Debug.Log()
输出警告 Deubg.LogWarning("44444")
输出错误 Deubg.LogError("44444")
使用这三种类型的输出来更好地调试游戏
Unity 控制台 右上角 三个 白、黄、红 的小按钮,对应:提示、警告、错误。按下某个按钮,控制台就会显示这一类的信息。只按下白色,就只显示
支援C# script
两个整数相除,小数部分会被自动舍去。
多个数据类型运算,返回的结果类型是数据类型大的。
//float res4 = 3 + 3.2f
文件名要和
void start 是初始化 void update 是
if(判断条件)
{
中间代码
}
else//另外
{
代码
}
int[] array = new int[10];
print(array[0]);
int[] arr = null;
int[] arrays = { };
print(arr);
print(arrays);
int[] hp = new int[5] { 1, 2, 3, 4, 5 };
数组
int[] hps = {100,20,80,9030};//数组长度是5.
通过索引访问数据:数组名[索引]。
举例:
int[] hps = { 100, 40, 80, 90, 20 };
print(hps[1]);
int a = 3;
float b = 2.1f;
float res = a + b;
print(res);//多个数据类型运算,返回结果类型是数据类型大的。
数据类型
C#有15个预定义类型,13个值类型,2个引用类型(string和object)。
1、整型:8个不同范围的整数类型。
2、浮点类型:float和doubl
日志:
Debug.Log("11111"):任意类型的方法中都可以输出。
Debug.LogWarning("11111"):警告输出。
Debug.LogError("11111"):错误输出。
print("11111")
利用类声明的变量-对象;
Enemy enemy1 = new Enemy();
使用变量前一定要初始化,也就是给变量fu zhi
申明变量
日志输出fang f
Print();输出 (只能在MonoBehaviour类下使用)
Debug.Log()输出 (任意类下都能使用)
Debug.LogWarning ⚠️输出警告
Debug.LogError ❌输出错误