Create a gist now

Instantly share code, notes, and snippets.

@tsubaki /Data.cs
Last active Nov 6, 2015

What would you like to do?
シーン間のデータ共有(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