Unity学习笔记

来源:互联网 发布:普罗米修斯剧情 知乎 编辑:程序博客网 时间:2024/05/26 07:28

初学者,用来做笔记的


1.在一个类里调用其他类的方法:

第一种,被调用脚本函数为static类型,调用时直接用  脚本名.函数名()

第二种,GameObject.Find("脚本所在的物体的名字").SendMessage("函数名"); //能调用public和private类型函数

第三种,GameObject.Find("脚本所在的物体的名字").GetComponent<脚本名>().函数名(); //只能调用public类型函数

2.移动物体:

transform.Translate(Vector3.down(方向)* speed * Time.deltaTime); 

3.移动物体到指定坐标:

update{

float step = speed * Time.deltaTime;


transform.position = Vector3.MoveTowards(transform.position
(当前位置), new Vector3(0, 2.5f, 0)(目标位置), step);

}

4.实例化物体

GameObject.Instantiate(Prefab(GameObject), new Vector3(x,y,z), Quaternion.identity);

5.重复调用方法

InvokeRepeating("方法名",1(几秒后调用),1(调用间隔))

CancelInvoke("方法名")//取消Invoke

6.背景轮换

void Update () {
        this.transform.Translate(Vector3.down*moveSpeed*Time.deltaTime);
        Vector3 positon = this.transform.position;
        if (positon.y <= -8.52f) {
            this.transform.position = new Vector3(positon.x, positon.y + 8.52f * 2, positon.z);
        }

}




0 0
原创粉丝点击