Unity 全局变量的应用

从 Scene2 回到 Scene1 ,不需要重载Scene1,直接回到 想要回到的面板

1、创建一个 全局的脚本 

global.cs2

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public class Global
{
    //仅显示一个面板
    public static bool ShowOnlyLevelPanel { get; set; }

{

2、创建一个 响应事件的脚本

GameSceneManager.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GameSceneManager : MonoBehaviour
{
    
    public void SceneBackStartGameToMapSelect()
    {
        Globle.ShowOnlyLevelPanel = true;
        SceneManager.LoadScene("StartGame");
    }
}

3. 创建 一个  具体执行的脚本

GameManager.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class GameManager : MonoBehaviour
{
    void Start()
    {
        Panel1 = Panels.MainPanleAni;

        if(Globle.ShowOnlyLevelPanel)
        {
            //只显示 MapSelect 一个面板
            Panel1 = Panels.MapSelect;
            //清除全局变量(可省)
            Globle.ShowOnlyLevelPanel = false;
        }
      
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值