[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
作者:lizhenghao126
出处:https://www.cnblogs.com/lizhenghao126/p/11053663.html
版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。
https://github.com/li-zheng-hao
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)