Last active
November 6, 2015 17:47
-
-
Save tsubaki/d26be15bfb4975ba81c0 to your computer and use it in GitHub Desktop.
シーン間のデータ共有(static)
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 Data | |
{ | |
public readonly static Data Instance = new Data(); | |
public int score = 0; | |
public string name = string.Empty; | |
} |
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; | |
// データをstaticに格納してシーンを呼ぶ側 | |
public class LoadScene : MonoBehaviour | |
{ | |
void Awake() | |
{ | |
Data.Instance.score = 30; | |
Data.Instance.name = "toppo"; | |
} | |
// click callback | |
public void OnClick() | |
{ | |
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; | |
// 受け取る側 | |
public class ReadData : MonoBehaviour | |
{ | |
void Start () | |
{ | |
Debug.Log (Data.Instance.score); | |
Debug.Log (Data.Instance.name); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment