类型【】数组名={数组值}保存多个值
print(hps[n]) 输出数组中的第n+1个数组
类型【】数组名={数组值}保存多个值
print(hps[n]) 输出数组中的第n+1个数组
/小数部分自动舍去
bool 表示是或否
char 可以存储字符 单引号
string 储存字符串(双引号)
数据类型不同对游戏内存的要求不同
选中 ctrl+k ctrl+c 注释
变量
类型 名字(不能数字开头)=赋的值
有mondbehaviour 可以直接print
Debug.log 可以任何情况下用=print
Debug.logWaring 警告 用于代码容易出错的地方
Debug.logError 报错
//单行注释
/*
*
*/多行注释
禁用组件:
组件名 命名 = 物体.GetComponent<组件名>();
命名.enabled = false;
访问自身组件:
组件名 命名 = GetComponent<组件名>();
得到子物体:
Transform[] children = transform.GetComponentsInChildren<Transform>();
销毁子物体:
GameObject.Destory(children[i].gameObject);
返回值 方法名(参数){
方法体
}
例:
void Test(){
print("");
}
引用:方法名();
引用类:
类名(new 参数)
看3分50秒
记得看课时19.
定义枚举类型:
enum 自行定义{
...............自己写..............
}
引用:
自行定义 名称 = 自行定义.自己写的;
会输出自己写的,名称可以重新赋值
||
主类 : xxxx 继承
类似结构体
类的命名:驼峰型
方法(函数):
void start/Update
返回值 方法名(参数)
{
方法体
}
例:
void CreateEnemy(){
print(“创建敌人”);
print(“设置位置”);
print(“初始属性”);
}
数组声明方法1.类型[ ] 数组名={ }
2.类型[ ] 数组名=new 类型[ ]
ps:int[ ] hps ={ } 不等于 int[ ] hps;后面那个的数组是不存在的没有预设的。前面那个是空数组,长度为0的数组
c#动态取数组长度:数组名+Length
bool 布尔型 true或false
string 字符型
float 浮点型
比较预算符
> < >= <= == !=
等于 不等于
int hp =100;
bool res =hp>0;
print(res);
int hp = 100;
hp = hp+ 10;//右边赋值给左边
hp += 10;//跟上面一样
print(hp);
hp -= 100;
print(hp);
hp++;//自增,自身增加1
print(hp);
hp--;
print(hp);
int