Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- /// <summary>
- /// Place this on GameObject in scene 1
- /// </summary>
- public class StaticScript : MonoBehaviour {
- public static StaticScript Instance = null;
- // Use this for initialization
- void Start () {
- Debug.Log (string.Format("{0} was created in scene {1}", this.gameObject.name, Application.loadedLevelName));
- Instance = this;
- Debug.Log ("Loading scene 2");
- Application.LoadLevel("2");
- }
- // Update is called once per frame
- void Update () {
- }
- }
- /// <summary>
- /// Place this on GameObject in scene 2
- /// </summary>
- public class AnotherScript : MonoBehaviour {
- // Use this for initialization
- void Start () {
- Debug.Log (string.Format("{0} was created in scene {1}", this.gameObject.name, Application.loadedLevelName));
- Debug.Log ("Accessing StaticObject that was created in previous scene");
- var staticObject = StaticScript.Instance;
- Debug.Log ("StaticObject: " + staticObject);
- Debug.Log ("GameObjet name of StaticObject: " + staticObject.gameObject.name); // Fail
- }
- // Update is called once per frame
- void Update () {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment