Unity 3D学习日记(4)

Day4

1.代码优化

2.发布(File-Build Settings)

3.添加天空盒子
导入包(Assets-Import Package-Skyboxes)
Window-Lighting

4.碰撞检测函数 void OnCollisionEnter(){

}

5.if(GUI.Button(new Rect(位置,位置,长,宽),”String Text”)))

6.调整场景发布顺序:从上而下(0 1 2 3…)

void Update () {
        GameObject.Find ("Canvas/Text").GetComponent<Text>().text="Instruction\n W:Forward, A:Left, S:Back, D:Right \nDestroy 6 items\nDon't touch the Capsule!";

    }

    void OnGUI(){
        if (GUI.Button (new Rect (400, 300, 100, 60), "Start")) {
            Application.LoadLevel ("01");

        }
        if (GUI.Button (new Rect (600, 300, 100, 60), "Quit")) {
            Application.Quit ();
        }

    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class SheXiangJi : MonoBehaviour {
    public Transform newobject;
    // Use this for initialization
    void Start () {
    }
    public int speed =5;
    public int NOB=0;         //Number of bullet
    public int NOD=0;         //Number of destroyed brick
    // Update is called once per frame
    void Update () {
        //"Camera translate"
        float x = Input.GetAxis ("Horizontal") * Time.deltaTime * speed;
        float z= Input.GetAxis ("Vertical") * Time.deltaTime * speed;
        transform.Translate (x,0,z);
        //print (x);

        //Shoot bullet
        if (Input.GetButtonDown ("Fire1")) {
            Transform n = Instantiate (newobject,transform.position,transform.rotation);
            Vector3 fwd = transform.TransformDirection (Vector3.forward);
            n.GetComponent<Rigidbody>().AddForce (fwd*5000);
            //Number of bullet
            NOB++;
            GameObject.Find ("Canvas/NOB").GetComponent<Text> ().text = "Number of bullet: " + NOB + " Number of destroyed brick:" + NOD;
        }

        //Rotate in Y using Q and E
        if(Input.GetKey(KeyCode.Q)){
            transform.Rotate (0,-25*Time.deltaTime,0,Space.Self);
        }
        if(Input.GetKey(KeyCode.E)){
            transform.Rotate (0,25*Time.deltaTime,0,Space.Self);
        }

        //Rotate in X using Z and C
        if(Input.GetKey(KeyCode.Z)){
            transform.Rotate (-25*Time.deltaTime,0,0,Space.Self);
        }
        if(Input.GetKey(KeyCode.C)){
            transform.Rotate (25*Time.deltaTime,0,0,Space.Self);
        }

        //Raise or down camera
        if (Input.GetKey (KeyCode.H)) {
            transform.Translate (0,speed*Time.deltaTime,0);
        }
        if (Input.GetKey (KeyCode.N)) {
            transform.Translate (0,-speed*Time.deltaTime,0);
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值