Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active November 6, 2015 17:47
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/d26be15bfb4975ba81c0 to your computer and use it in GitHub Desktop.
Save tsubaki/d26be15bfb4975ba81c0 to your computer and use it in GitHub Desktop.
シーン間のデータ共有(static)
using UnityEngine;
using System.Collections;
public class Data
{
public readonly static Data Instance = new Data();
public int score = 0;
public string name = string.Empty;
}
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);
}
}
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