Last active
August 29, 2015 14:01
-
-
Save tsubaki/d7645bdafd8ed366c605 to your computer and use it in GitHub Desktop.
DontDestroyParentのサンプル。SingletonMonobehaviourを利用
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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