unity实例1-quanmingongdou
跳转界面脚本和变量脚本
1.JumpInterface.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;//定义控件用
using UnityEngine.SceneManagement;//跳转界面用
public class JumpInterface : MonoBehaviour
{
//跳转男宠界面
public void toHandsomeManGame()
{
SceneManager.LoadScene("HandSomeManGame");
}
//跳转换装界面
public void toDressGame()
{
SceneManager.LoadScene("DressGame");
}
//跳转练级界面
public void toLevelingGame()
{
SceneManager.LoadScene("LevelingGame");
}
//跳转约会界面
public void toAppointmentGame()
{
SceneManager.LoadScene("AppointmentGame");
}
//跳转主界面
public void toMainGame()
{
SceneManager.LoadScene("MainGame");
}
}
2.VariableDocument.cs
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class VariableDocument : Single<VariableDocument> //Single 单一的
{
//魅力//外貌//情缘//好感
public int[] attributes = {
20, 19, 43, 29 };
//等级
public int Grade()
{
return (attributes[0] + attributes[1] + attributes[2] + attributes[3]) / 100;
}
//记录当前服装
public int clothNum = 1;
//角色立绘图
public string[] roleImgAdress = {
"Dress/11", "Dress/22", "Dress/33", "Dress/44", "Dress/55", "Dress/66", "Dress/77", "Dress/88", "Dress/99" };
//敌人失败次数
public int enemyFailNum = 1;
//所有男宠Assets/Resources/Appointment/千里.png
public string[,] allHandsomeMen =
{
{
"千里", "Appointment/千里"},
{
"泰也", "Appointment/泰也"},
{
"焰卫", "Appointment/焰卫"},
{
"终南", "Appointment/终南"},
{
"英招", "Appointment/英招"},
{
"雅鲁", "Appointment/雅鲁"},
};
}
//单例模式
public class Single<T> where T : new()
{
private static T instance;
public static T GetInstance
{
get
{
if (instance == null)
{
instance = new T();
}
return instance;
}
}
}
开始界面-StartGame
界面
1.新建Scenes,命名为StartGame,此界面主要功能:进度条加载/界面跳转
2.Ctrl+Shift+B,选择iOS,点击switch platform,游戏视图屏幕尺寸选择1334×750
3.点击右键-UI-Image,命名为StartGameBackground,设定尺寸为全画布,Source Image设定为background1。
4.Canvas的Canvas Scaler-UI Scale Mode设定为Scale with screen size, Reference Resolution设定为1334×750
5.新建Button,命名为Startbtn, PosX:0, PosY:-250, Width:248, Height:108,Source Image: anniu.
6.新建Panel,尺寸为全画布,设置为透明(Image-Color-A为0),panel下新建Slider,命名为LoadingBar,控件Background的Source Image设定为色相_饱和度-22, 控件Fill Area的尺寸设定为left:0,right:0,控件Fill的Source Image设定为色相_饱和度-21,删掉Handle Slide Area控件.
7.隐藏panel
脚本
StartScript.cs,注意⚠️此脚本需要附在panel或LoadingBar上,不然会一运行就走loading
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;//定义控件用
using UnityEngine.SceneManagement;//跳转界面用
public class StartScript : MonoBehaviour
{
public GameObject startPanel;
public Slider loadingBar;
public GameObject startBtn;
// Update is called once per frame
void Update()
{
Loading();
}
//点击开始游戏按钮,隐藏开始游戏图标并显示panel,加载进度条
public void ClickStartBtn()
{
startBtn.SetActive(false);
startPanel.SetActive(true);
}
//加载进度条,当进度条满跳转到主界面
public void Loading()
{
loadingBar.value += 0.01f;
if (loadingBar.value >= 0)
{
SceneManager.LoadScene("MainGame"