索引 0是第一个数
索引 0是第一个数
常用数值类型
int hp = 100; 整型
float hp1 = 3.4f; 浮点型
bool hp2 = true or false; 布尔型
char hp3 = 'c';字符型
string hp4 = "绝地武士";字符串型
选中多行注释Ctrl + k Ctrl + c
变量:类型 变量名(字母开关) = 值
单行注释"//";
多行注释"/* */";
输出方式:
print(); 必须类继承MondBehaviour方可使用 ( :MondBehaviour
Debug.Log(); 在任意地方都可使用
Debug.LogWarning(); 同上,有警告意义
Debug.LogError(); 同上,提示错误
print 输出
debug.log 输出 适用所有
debug.logwarning 警告
debug.logerror 错误
小数float类型后面跟
s k c
debug.logereror
debug.logwaarning
debug.log
类名与 脚本名一致
http://www.cnblogs.com/tonney/archive/2011/03/19/1987577.html
1)拖拽
2)transform.Find("xx");//查找子物体,xx标明路径
3)GameObject.Find("name");//不推荐,效率低
4)GameObject.FindWithTag("Player");//标签,比全局搜索节约性能
数组的声明:
int[] a = new int [10];
int[] a = new int [2] {1,2};
数组声明方式:
数据类型[] 数组名 = {数组值}
int[] a = {1,2,3};
数据类型:
int a = 100;
float b = 3.14f;
bool c = false;
char d = ‘d’
sting e = “aaa”
日志输出方法:
Debug.Log()以普通信息方式输出
Debug.LogWarning()以警告信息方式输出
Debug.LogError()以错误信息方式输出
foreach(Transform t in children)
{
if(t != transform)
Destroy(t.gameobject);
}
1.利用循环销毁
void Start(){
Transform [] children = transform.GetComponentsInChildren<Transform>();
//第一种
for(int i=0;i<children.Length;i++)
{
if(children[i]!=transform)
GameObject.Destory(children[i].gameobject);
}
//第二种
int i=0;
while(i<children.Length)
{
if(children[i]!=transform)
GameObject.Destory(children[i].gameobject);
}
//第三种
int i=0;
do
{
if(children[i]!=transform)
GameObject.Destory(children[i].gameobject);
}
i++;
}
while(i<children.Length);
}
方法中的
访问对象的名字的话
在class类里的string必须是public string
Enemy enemy1 = new Enemy();
print(enemy1.name)这样输出是null
没有赋初值的时候string类型输出Null
而像血量这样的数字,没有赋初值得到的值是0
类的定义,在Enemy这个类型里有两个数据
class Enemy{
string name;
int hp;
}
这个类型的调用
Enemy enemy1 = new Enemy();
创建一个关于敌人的类