Unity 3D学习日记(3)

来源:互联网 发布:人参出口韩国数据 编辑:程序博客网 时间:2024/05/29 08:30

Day3

1.int x=0;
if(Input.GetButtonDown(“Fire1”)){
x=x+1;

}

2.访问物体以及物体的组件
gameObject.Find(“NOB”).GetComponent(GUIText)=”子弹数”+x;
C#版:GameObject.Find (“Canvas/NOB”).GetComponent().text = “Number of bullet: ” + i;

3.实现消灭计数 int NOD=0
if(GameObject.transform.position.y<0){
GameObject.Find(“Main Camera”).GetComponent().NOD++;

}

4.GameObject.Find().GetCompnent<>().enable=false;

5.添加按钮 屏幕左上角是(0,0),(x,y,长,宽)
void OnGUI()
if(GUI.Button(Rect(180,100,60,30),”Quit”)){
Application.Quit();
}
if(GUI.Button(Rect(280,100,60,30),”Restart”)){
Application.LoadLevel(“01”);//重新加载场景
}
gameObject.GetCompnent().Play();
audio.Pause();
audio.Stop();

6.添加声音 添加Audio Source
Play On Awake自动播放
Loop 循环播放

    void OnGUI(){        //Quit and Restart game        if(GUI.Button(new Rect(0,100,60,30),"Quit")){            Application.Quit();        }        if(GUI.Button(new Rect(60,100,60,30),"Restart")){            Application.LoadLevel("01");        }        if(GUI.Button(new Rect(100,130,70,50),"Play")){            gameObject.GetComponent<AudioSource> ().Play();        }        if (GUI.Button (new Rect (100, 200, 70, 50), "Pause")) {            gameObject.GetComponent<AudioSource> ().Pause();        }        if (GUI.Button (new Rect (100, 270, 70, 50), "Stop")) {            gameObject.GetComponent<AudioSource> ().Stop();        }    }
原创粉丝点击