Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/d7645bdafd8ed366c605 to your computer and use it in GitHub Desktop.
Save tsubaki/d7645bdafd8ed366c605 to your computer and use it in GitHub Desktop.
DontDestroyParentのサンプル。SingletonMonobehaviourを利用
using UnityEngine;
using System.Collections;
// シーン1のGUI
public class GUIController : SingletonMonoBehaviour<GUIController> {
void OnGUI()
{
GUILayout.BeginHorizontal();
if(GUILayout.Button( "add score: " + ScoreController.Instance.score, GUILayout.Height(50) ))
{
ScoreController.Instance.score ++ ;
}
GUILayout.EndHorizontal();
if( GUILayout.Button("go next scene") )
{
// スコアコントローラーは一時保存
this.DontDestroyOnNextLoad(ScoreController.Instance);
Application.LoadLevel(1);
}
}
}
using UnityEngine;
using System.Collections;
// シーン2のGUI
public class ResultGUIController : SingletonMonoBehaviour<ResultGUIController> {
public GUIText guiText = null;
void Start()
{
guiText.text = ScoreController.Instance.score.ToString();
}
void OnGUI()
{
if( GUILayout.Button("go back scene") )
{
Application.LoadLevel(0);
}
}
}
using UnityEngine;
using System.Collections;
// スコア
public class ScoreController : SingletonMonoBehaviour<ScoreController>
{
public int score = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment