错题总结

来源:互联网 发布:给游戏做美工需要什么 编辑:程序博客网 时间:2024/05/16 16:08

      错题总结

1void FixedUpdate()更新是固定的,更新频率是0.02秒

void Update ()更新是不固定的,时快时慢。

2类,对象,方法,返回值

    GameObject go= GameObject.Instantiate(cube,transform.position,Quaternion.identity) as GameObject;

解析:1 所有方法的游戏对象都是GameObject.

2 Instantiate是方法名克隆

3cube,transform.position,Quaternion.identity是3个参数

4GameObject.Instantiate(cube,transform.position,Quaternion.identity)是创建(克隆)了关于cube的东西。

5 GameObject go= GameObject.Instantiate(cube,transform.position,Quaternion.identity) 是给创建的东西起个名字并且赋值(返回值)

6 as GameObject;这句话语句有错需要强制转换。

3Unity3D中GameObject Sun与Public GameObject Sun不一样。都可以声明,但是前者默认是私有的。

4毁灭物体

  void OnTriggerEnter(Collider c)//c对象指的是敌人。

<span style="font-size:18px;">    {                if (c.tag == "Finish")//Finish指的是敌人的标签(tag)        {            Destroy(c.gameObject);//c.gameObject指的是敌人而this.gameObject指的是自己本身。            i++;            print("吃掉第" + i + "个食物");//变量中加变量需要用到”+后一个变量+”            if (i == 8)            {                print("you win!");            }        }    }</span>

5碰撞检测

         创建的模型用要加盒子,而系统自带的cube,spere等都自带有盒子。

水平垂直移动。

       float height = 0;

       float x = Input.GetAxis("Horizontal") * Time.deltaTime *speed ;

       float z = Input.GetAxis("Vertical") * Time.deltaTime * speed;

        transform.Translate(new Vector3(x, height, z));

7用Time类实现倒计时5秒后实现一个游戏物体向另一个游戏物体(同级别的)发送信息

解析:发送、接受消息需要两个脚本(声明接受者对象)。

<span style="font-size:18px;"><span style="font-size:18px;"><strong>using UnityEngine;发消息者sphereusing System.Collections;public class Sixth : MonoBehaviour{     public GameObject cube;    float a = 5.0f;    void Update()    {        a -= Time.deltaTime;        if (a <= 0)        {            cube.SendMessage("Do", "you are ?");        }    }}using UnityEngine;接收消息者 cubeusing System.Collections;public class Sixth2 : MonoBehaviour {    void Do(string message )     {               print(message);    }}</strong></span></span>









 以上是数据库的初步了解,如果你有什么不会的话,可以来狗刨学习网上来看看,如果你想在Unity3D上大展手脚的话,可以来狗刨培训与专家咨询。

0 0
原创粉丝点击