您的位置:首页 > 移动开发 > Unity3D

Unity学习笔记

2017-01-04 16:12 471 查看
初学者,用来做笔记的

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);

        }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: