Last active
June 17, 2019 18:51
-
-
Save pr00thmatic/23a22f6b26a157b994e7bde11e1abfb0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public static GameObject SafePrefabInstantiate(GameObject reference){ | |
return SafePrefabInstantiate(reference,Vector3.zero,Quaternion.identity); | |
} | |
public static GameObject SafePrefabInstantiate (GameObject reference, | |
Vector3 position, | |
Quaternion rotation) { | |
#if UNITY_EDITOR | |
if (Application.isPlaying) { | |
return GameObject.Instantiate(reference, position, rotation); | |
} else { | |
GameObject obj = PrefabUtility.InstantiatePrefab(reference) as GameObject; | |
obj.transform.position = position; | |
obj.transform.rotation = rotation; | |
return obj; | |
} | |
#else | |
return Instantiate(reference); | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment