#Thread
1 messages · Page 1 of 1 (latest)
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
Oh how neat
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;
Oh my
lmk if that works
What was the error message?
Oh boy lol
by the looks of it, the curly bracket should go at the very end of the file, after the last #endif
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
Oh thanks! that's really helpful
yep np, gl