创建场景
-
新建四个场景
-
打开构建配置文件
-
将新创建的四个场景依次添加到列表里
MainMenu主菜单
-
创建UI-图像
-
其中一个命名为BG背景,再复制一个命名为Botton按钮组
-
把BG和Botton的位置都调成0,0,0
-
给BG下面创建一个UI-图像
-
把背景1添加到源图像
-
点击设置原生大小,调整大小如图,把BG和Botton的Image勾掉,去掉白色图块
-
依次添加背景的四个部分
-
调整背景颜色,选中MainCamera,将颜色改为土黄色
-
创建Logo、人物、光圈,背景
主菜单动画
-
添加角色呼吸动画,选中Role,按下ctrl+6
-
创建一个Animations文件夹
-
点击创建,在Animations文件夹底下,Role.anim
-
点击录制
-
在0秒将Role变得瘦高,在1秒使变得矮胖
-
点击关闭录制,将第一帧的内容复制到第120帧
-
同理,给BGFront和BGBack添加左右移动动画,Front在240帧和480帧添加帧,使其从左向右再返回,Back正好相反
按钮设置
-
在Botton下面新建一个按钮
-
给Buttons再右边添加Vertical Layout Group组件
-
点击字体资产创建工具
-
点击创建字体
-
选中Text,在右边选择Alibaba字体
-
替换按钮的正常颜色为RGB8,7,8,文字颜色换为白色
-
复制出3个按钮
-
通过Vertical组件调整按钮间距
-
更改其他按钮的内容
按钮交互
- 新建一个Scripts文件夹,新建一个CommonButton脚本吗,将其挂载到四个按钮组件上
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class CommonButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
private Image image;
private TextMeshProUGUI text;
private void Awake()
{
image = GetComponent<Image>();
text = GetComponentInChildren<TextMeshProUGUI>();
}
public void OnPointerEnter(PointerEventData eventData)
{
image.color = new Color(255, 255, 255);
text.color = Color.black;
}
public void OnPointerExit(PointerEventData eventData)
{
image.color = Color.black;
text.color = new Color(255, 255, 255);
}
}
按钮跳转
-
将Button重命名为MainMneuPanel
-
创建一个同名脚本
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class MainMenuPanel : MonoBehaviour
{
private Button startButton;
private Button settingsButton;
private Button progressButton;
private Button exitButton;
private void Awake()
{
startButton = GameObject.Find("StartButton").GetComponent<Button>();
settingsButton = GameObject.Find("SettingsButton").GetComponent<Button>();
progressButton = GameObject.Find("ProgressButton").GetComponent<Button>();
exitButton = GameObject.Find("ExitButton").GetComponent<Button>();
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
startButton.onClick.AddListener(() =>
{
SceneManager.LoadScene("02-LevelSelect");
});
}
// Update is called once per frame
void Update()
{
}
}
- 将其挂载到MainMenuPanel上