[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

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值