美文网首页unity3D
Uinty的uGUI学习(08):案例-游戏设置界面

Uinty的uGUI学习(08):案例-游戏设置界面

作者: liyuhong165 | 来源:发表于2017-04-24 18:00 被阅读140次
    一、uGUI - setting(设置界面)
    • 1.使用的控件
    text
    slider
    Toggle
    (create empty child)空的游戏物体
    

    14_1设置界面的布局.png
    二、uGUI - 处理事件(设置界面)
    • 1.事件的处理 我们在方法里面获取的值,拿不到.所以需要获取系统(动态的方法的值)
    带有参数的方法。
    我们需要去动态的去创建动态的方法。
    

    GameController脚本

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;  // 导入UI类
    
    public class GameController : MonoBehaviour {
    
    // 属性
        public InputField if_user;
        public InputField if_pwd;
    
        public Text showmessage;
    
    // 按钮点击
        public void OnLoginButtonClock()
        {
            string username = this.if_user.text; // username.text 错误写法 ,因为 username 是一个局部变量 我们要使用外部变量需要加上this.,访问属性
            string passwrod = this.if_pwd.text;
    
            if (username == "admin" && passwrod == "admin") {
                // 登录成功之后,跳转到游戏界面
                print("登录成功之后,跳转到游戏界面");
    
            } else {
                showmessage.gameObject.SetActive(true);
                showmessage.text = "你的用户名或者密码错误,请重新输入";
                StartCoroutine (DisappearMessage ());
    
            }
        }
    
    // 用来消失message文本的
        //  IEnumerator 迭代器
        // 所以yield关键词是干啥的?它声明序列中的下一个值或者是一个无意义的值。
        IEnumerator DisappearMessage()
        {
            yield return new WaitForSeconds (1);
            showmessage.gameObject.SetActive (false);
        }
    
    // 静音 
        public void OnSoundOff(bool isActive){
            // isActive 开的 就是静音
            // isActive off 就是不静音 
            print(isActive);            
        }
    // 声音
        public void OnSoundValueChange(float value)
        {
            print(value);           
        }
    // 游戏难度
        // 容易
        public void OnEazyChange(bool isActive)
        {
            print("容易"+isActive);           
        }
        // 一般
        public void OnNormalChange(bool isActive)
        {
            print("一般"+isActive);           
        }
        // 困难
        public void OnDifficulChange(bool isActive)
        {
            print("困难"+isActive);           
        }
    
    }
    
    
    15_1自定义带有参数的方法绑定到事件里面去_选择Dynamic.png 15_2控制台打印.png

    15_3控制台打印.png

    相关文章

      网友评论

        本文标题:Uinty的uGUI学习(08):案例-游戏设置界面

        本文链接:https://www.haomeiwen.com/subject/qqetzttx.html