やまめも

【 ゲーム開発・日々のことについて 】

それぞれのシーンに相当するオブジェクトの親をオンオフして、表示の切り替えをする。

UIの親につけるスクリプト
UIAchievementMenu.cs

using UnityEngine;
using System.Collections;

public class UIAchievementMenu : MonoBehaviour {

	private GameObject _container ;
	void Awake(){
		_container  = transform.FindChild("Container").gameObject;
		_container.SetActive(false);
	}

	void OnEnable(){

		EventManager.onGameChangeSceneEvent += HandleonGameChangeSceneEvent;
	}
	void OnDisable(){
		
		EventManager.onGameChangeSceneEvent -= HandleonGameChangeSceneEvent;
	}
	void HandleonGameChangeSceneEvent (GameController.GAME_SCENE scene){
		switch(scene){
		case GameController.GAME_SCENE.GAME_SCENE_ACHIEVEMENT_MENU:
			_container.SetActive(true);
			break;
		default:
			_container.SetActive(false);
			break;
		}
	}
}


ボタンの付いているスクリプトにつける
HUDClass.cs

	public void OnAchievementButtonClick(){
		EventManager.GameChangeSceneMethod(GameController.GAME_SCENE.GAME_SCENE_ACHIEVEMENT_MENU);
	}

GameController.cs

using UnityEngine;
using System.Collections;

public class GameController : MonoBehaviour {
	public enum GAME_SCENE{
		GAME_SCENE_TITLESCREEN,
		GAME_SCENE_STAGE_SELECTION,
		GAME_SCENE_INGAME,
		GAME_SCENE_PAUSE,
		GAME_SCENE_EXIT_MENU,
		GAME_SCENE_HERO_UPGRADE_MENU,
		GAME_SCENE_RESULT_SCREEN,
		GAME_SCENE_ACHIEVEMENT_MENU

	}

	public static GAME_SCENE _curGameScene = GAME_SCENE.GAME_SCENE_TITLESCREEN;
	public static GAME_SCENE _prevGameScene = GAME_SCENE.GAME_SCENE_TITLESCREEN;

	public static int _stage = 1;
	public static GameController Instance;
	public float _autoSaveCounter = 1f;
	void Awake(){
		Instance = this;
	}
	void OnEnable(){
		EventManager.onGameChangeSceneEvent += HandleonGameChangeSceneEvent;
	}
	void OnDisable(){
		EventManager.onGameChangeSceneEvent -= HandleonGameChangeSceneEvent;
	}

	void HandleonGameChangeSceneEvent (GAME_SCENE scene)
	{
		_prevGameScene = _curGameScene;
		_curGameScene = scene;
	}
}