There is one issue that you should be aware of. PrefabStageUtility is in the namespace UnityEditor.SceneManagement When you build a project to be a standalone player, Editor code is not allowed. The compiler will just ignore the
using UnityEditor;
but will not automatically remove any code that relies on Editor code, and will not automatically remove
using UnityEditor.SceneManagement;
You can get around this by surrounding any Editor code with
#if UNITY_EDITOR
using UnityEditor.SceneManagement;
#endif
and
#if UNITY_EDITOR
if (PrefabStageUtility.GetPrefabStage(gameObject)) return;
#endif
Now in this instance, I believe we’re in the middle of an if #UNITY_EDITOR block so you’ll just need to surround the using clause in an #if block.