切换并激活,现在看来有难度!还是必须解决的。
初步想法是挂在camera上,camera上的脚本在初始化是隐藏下层canvas,这是Update还一直可以使用,利用state标志位进行判断(决定是否显示canvas) ,实际结果证明确实是可行的。
相机上的脚本如下,全是技巧:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SelectMenu : MonoBehaviour
{
// Start is called before the first frame update
//public GameObject c = GameObject.FindWithTag("selectMenuCanvas");
public GameObject quan;
public int flag = 0;
void Start()
{
//gameObject.SetActive(false);
//GameObject m = GameObject.FindWithTag("selectMenuCanvas");//现在我挂在camera上就可以这么用了
this.quan = GameObject.FindWithTag("selectMenuCanvas");//同一命名空间即可,canvas在最外边是有道理的
this.quan.SetActive(false);
//gameObject.GetComponent<Renderer>.enabled = false;
}
// Update is called once per frame
void Update()//角色的选择和创建我做在一起就可以了
{
//Debug.Log(GameInfo.GAME_STATE);//初始状态开始为0
//Debug.Log(GameState.PLAYER_CREATE); //这个是4
if (GameInfo.GAME_STATE == GameState.PLAYER_CREATE && this.flag == 0)
{
//Debug.Log(GameInfo.GAME_STATE);//初始状态开始为0
//Debug.Log(GameState.PLAYER_CREATE);
this.flag = 1;
Debug.Log("这里计划是只执行一次");
this.quan.SetActive(true);
}
}
}
场景跳转部分的代码如下:(提前修改了一下全局状态位而已)
IEnumerator load(int level){
//async = Application.LoadLevelAsync (level);//这里的1是在build setting中设置的。
Debug.Log("好像是死在这里了!");
// async = Application.LoadLevelAsync(level);
//yield return async;
//AsyncOperation operation = SceneManager.LoadSceneAsync(level, LoadSceneMode.Additive);
if (level == 1)
{
GameInfo.GAME_STATE = GameState.PLAYER_CREATE;//1号场景是
}
AsyncOperation operation = SceneManager.LoadSceneAsync(level);
Debug.Log("切换到新场景中!");
yield return operation;
}
至此,所有功能正常。
本文含有隐藏内容,请 开通VIP 后查看