Created
April 17, 2015 18:42
-
-
Save mikelovesrobots/f8aeb8cc5ccb1b97bc61 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 for Unity3d 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 need to talk to Parse in | |
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
Thanks! It worked for us