Unity 3D学习日记(3)

编程入门 行业动态 更新时间:2024-10-22 21:29:38

Unity 3D学习<a href=https://www.elefans.com/category/jswz/34/1768372.html style=日记(3)"/>

Unity 3D学习日记(3)

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 gameif(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();}}

更多推荐

Unity 3D学习日记(3)

本文发布于:2024-02-24 18:57:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1696345.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日记   Unity

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!