Skip to content

Instantly share code, notes, and snippets.

@snlehton
Created April 2, 2015 14:41
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 snlehton/b867a596df079993873a to your computer and use it in GitHub Desktop.
Save snlehton/b867a596df079993873a to your computer and use it in GitHub Desktop.
SOExampleBehaviour v2
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class SOExampleBehaviour : MonoBehaviour
{
public SOExample test;
public void OnEnable()
{
// find existing instance if needed
if (test == null)
test = Object.FindObjectOfType<SOExample>();
// then instantiate if needed
if (test == null)
test = ScriptableObject.CreateInstance<SOExample>();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment