zoukankan      html  css  js  c++  java
  • Unity3D笔记 切水果 一

    最终效果:

    一、选择背景图片,选择GUI Texture 

    二、创建一个空的GameObject,然后添加背景音乐

    三、创建GUISkin

    四、主要代码

    #pragma strict
    
    var myGUI:GUISkin;
    
    private var isSound1Button:boolean=false;
    private var isSound2Button:boolean=true;
    private var sound:AudioSource;
          
    function Start () {
        sound=gameObject.GetComponent(AudioSource);//方法2创建的空GameObject 里面查找背景音乐
    }
    
    function Update () {
        
    }
    
    function OnGUI(){
        
        GUI.skin=myGUI;//通过前端把New GUISkin 赋值给mySkin 
        
        if(GUI.Button(Rect(390,250,220,66),"",GUI.skin.GetStyle("PlayButton"))){
            Application.LoadLevel(1);//或者 Application.LoadLevel("level1");   此时一定要把场景1添加到BuildSetting中
        }
        if(GUI.Button(Rect(350,330,320,66),"",GUI.skin.GetStyle("MoreButton"))){
            
        }
        if(GUI.Button(Rect(390,400,180,66),"",GUI.skin.GetStyle("CreditButton"))){
            
        }
         
        //默认是播放背景音乐
        if(isSound1Button){
            if(GUI.Button(Rect(30,500,37,30),"",GUI.skin.GetStyle("Sound1Button"))){
                audio.Play();
                isSound1Button=false;
                isSound2Button=true;
            }
        }
        if(isSound2Button){
            if(GUI.Button(Rect(30,500,47,30),"",GUI.skin.GetStyle("Sound2Button"))){
                audio.Stop();
                isSound1Button=true;
                isSound2Button=false;
            }
        }
        
        
        
    }

     from 龚老师视频


    作者:PEPE
    出处:http://pepe.cnblogs.com/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    学习Node.js笔记(一)
    HTML5的新特性及技巧分享总结
    前端切图的一些笔记(整理的有点乱)
    聊一聊前端速度统计(性能统计)那些事儿(转)
    jQuery中的checkbox问题
    随笔记录
    pillow模块快速学习
    Git学习及使用
    网站(陆续更新)
    ggplot笔记001——ggplot2安装
  • 原文地址:https://www.cnblogs.com/PEPE/p/3572776.html
Copyright © 2011-2022 走看看