Created
April 17, 2015 18:41
-
-
Save mikelovesrobots/274b40c23d64a09d58c3 to your computer and use it in GitHub Desktop.
ParseSafeInitializeBehaviour
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; | |
using Parse; | |
// Parse stops responding if it gets initialized twice or the original initialization goes away (e.g., you leave the scene) | |
// so use this instead of the regular ParseInitializeBehaviour, and throw it in every scene that you access Parse from | |
public class ParseSafeInitializeBehaviour : ParseInitializeBehaviour { | |
public static bool IsAlreadyAlive; | |
public override void Awake() { | |
if (IsAlreadyAlive) { | |
Destroy(gameObject); | |
return; | |
} | |
IsAlreadyAlive = true; | |
DontDestroyOnLoad(gameObject); | |
base.Awake(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment