zoukankan      html  css  js  c++  java
  • [Untiy]贪吃蛇大作战(二)——规则界面

    游戏规则界面:

    从界面上可以看出,一共有三个按钮,两个切换按钮和一个退出按钮。

    一共三张规则图片Sprite,我们通过设置其是否为Active来控制显示,其控制脚本代码如下:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    
    public class changePicture : MonoBehaviour {
        public RawImage bg1, bg2, bg3;
        private static int currentIndex=1;
    	public void BackPicture()
        {
           
            --currentIndex;
            if (currentIndex < 1)
                currentIndex = 1;
            switch (currentIndex)
            {
                case 1:
                    bg1.gameObject.SetActive(true);
                    bg2.gameObject.SetActive(false);
                    bg3.gameObject.SetActive(false);
                    break;
                case 2:
                    bg1.gameObject.SetActive(false);
                    bg2.gameObject.SetActive(true);
                    bg3.gameObject.SetActive(false);
                    break;
                case 3:
                    bg1.gameObject.SetActive(false);
                    bg2.gameObject.SetActive(false);
                    bg3.gameObject.SetActive(true);
                    break;
            }
        }
        public void NextPicture()
        {
           
            ++currentIndex;
            if (currentIndex >3)
                currentIndex = 3;
            switch (currentIndex)
            {
                case 1:
                    bg1.gameObject.SetActive(true);
                    bg2.gameObject.SetActive(false);
                    bg3.gameObject.SetActive(false);
                    break;
                case 2:
                    bg1.gameObject.SetActive(false);
                    bg2.gameObject.SetActive(true);
                    bg3.gameObject.SetActive(false);
                    break;
                case 3:
                    bg1.gameObject.SetActive(false);
                    bg2.gameObject.SetActive(false);
                    bg3.gameObject.SetActive(true);
                    break;
            }
        }
    }
    

    将对应的三张图片放上去即可。

    然后设置好返回界面的跳转(不要忘记canvas的适配哦!)

    这一个场景就这样完成了。


    第三章节:https://blog.csdn.net/m0_37316917/article/details/81285679

    https://github.com/li-zheng-hao
  • 相关阅读:
    字节跳动软开校招岗
    众安保险软开校招岗
    topjui中combobox使用
    easyui中datagrid+layout布局
    jquery/js记录点击事件,单击次数加一,双击清零
    java图片上传及图片回显1
    java格式化
    java中的String整理
    删除window10没用的服务
    修改mysql默认端口
  • 原文地址:https://www.cnblogs.com/lizhenghao126/p/11053663.html
Copyright © 2011-2022 走看看