#Thread

1 messages · Page 1 of 1 (latest)

clear mantle
#

First of all, this can be simplified down to just one Precompile Directive:

#if UNITY_EDITOR
    /// <summary>
    /// Rotate billboards to face editor camera while game not running.
    /// </summary>
    public void OnDrawGizmos()
    {
        if (!Application.isPlaying)
        {
            SceneView sceneView = GetActiveSceneView();
            if (sceneView)
            {
                // Editor camera stands in for player camera in edit mode
                Vector3 viewDirection = -new Vector3(sceneView.camera.transform.forward.x, 0, sceneView.camera.transform.forward.z);
                transform.LookAt(transform.position + viewDirection);
            }
        }

        Gizmos.color = Color.red;
        Gizmos.DrawRay(transform.parent.position, transform.parent.forward * 2);
    }

    private SceneView GetActiveSceneView()
    {
        // Return the focused window if it is a SceneView
        if (EditorWindow.focusedWindow != null && EditorWindow.focusedWindow.GetType() == typeof(SceneView))
            return (SceneView)EditorWindow.focusedWindow;

        return null;
    }
#endif
odd stag
#

Oh how neat

clear mantle
#

The line private SceneView GetActiveSceneView() must be included

#

That's because the return type is of type SceneView

#

When I say anything I mean anything and everything related to the editor, including using directives.

using UnityEditor;
odd stag
#

Oh my

clear mantle
#

lmk if that works

odd stag
#

Nope, may be my goofup tho

clear mantle
#

What was the error message?

odd stag
#

many many times

clear mantle
#

your missing a curly bracket

#

I think you deleted one by accident

odd stag
#

Oh boy lol

clear mantle
# odd stag

by the looks of it, the curly bracket should go at the very end of the file, after the last #endif

odd stag
#

Yup

#

Thank you so much, you're a lifesaver! It worked!

clear mantle
# odd stag Thank you so much, you're a lifesaver! It worked!

np glad to help haha. Little tip, if you're doing a bunch of debugging and getting tired of removing/adding Debug.Log etc you can put at the top of the file #define DEBUG (DEBUG can be any name) will allow you to "toggle" the debugging stuff. Remember, for #define DEBUG to do anything you need to have the code that you want to emit debug info to be between the #if and #endif directives. Example:

#define DEBUG_MY_CODE
// Top of file

public void SetPosition(Vector3 newPosition) {

#if DEBUG_MY_CODE
  Debug.Log("The new position is " + newPosition);
#endif

  transform.position = newPosition;
}

Debug.Log("The new position is " + newPosition); will only print to the console if the #define DEBUG_MY_CODE is defined. Really handy to know about.

#

To "disable" the debugging, remove or comment out the #define DEBUG_MY_CODE

#

This can of course also be used for literally anything

odd stag
#

Oh thanks! that's really helpful

clear mantle
#

yep np, gl