[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