Does anyone know how I can execute the AddWaypoint() from line 37 in the PathTool script? I can execute the CreateNewPath() on line 14 easily. But can't figure out how to execute from inside the OnScene() method. My spawner script: Code (CSharp): using UnityEngine; public class Spawner : MonoBehaviour { public void CreateNewPath() { // Do stuff } public void AddWaypoint(Vector3 position, Quaternion rotation) { // Do more stuff } } My editor script to add 2 buttons to my spawner script: Code (CSharp): using UnityEngine; using UnityEditor; [CustomEditor(typeof(Spawner))] public class PathTool : Editor { public override void OnInspectorGUI() { DrawDefaultInspector(); Spawner spawner = (Spawner)target; if (GUILayout.Button("Create New Path")) { spawner.CreateNewPath(); SceneView.duringSceneGui -= OnScene; SceneView.duringSceneGui += OnScene; } if (GUILayout.Button("Finish Adding Waypoints")) { SceneView.duringSceneGui -= OnScene; } } private static void OnScene(SceneView sceneview) { HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive)); if (Event.current.type == EventType.MouseDown) { Vector2 mousePosition = Event.current.mousePosition; Ray ray = HandleUtility.GUIPointToWorldRay(mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 10000f)) { // How to reach AddWaypoint() from here? } } } }
You can use Static variable to do that, just store the spawner in a static variable, something like this: Code (CSharp): using UnityEngine; using UnityEditor; [CustomEditor(typeof(Spawner))] public class PathTool : Editor { private static Spawner spawner; public override void OnInspectorGUI() { DrawDefaultInspector(); spawner = (Spawner)target; if (GUILayout.Button("Create New Path")) { spawner.CreateNewPath(); SceneView.duringSceneGui -= OnScene; SceneView.duringSceneGui += OnScene; } if (GUILayout.Button("Finish Adding Waypoints")) { SceneView.duringSceneGui -= OnScene; } } private static void OnScene(SceneView sceneview) { HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive)); if (Event.current.type == EventType.MouseDown) { Vector2 mousePosition = Event.current.mousePosition; Ray ray = HandleUtility.GUIPointToWorldRay(mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 10000f)) { // How to reach AddWaypoint() from here? // Here is how to reach AddWaypoint() if (spawner != null) { // Here you have full access to Spawner methods and properties. } } } } } Hope this helps. Regards.