Hi!
I’ve got an enemy that “patrols” left to right between two x coordinates (I’m working in 2D).

The two x coordinates are public variables that I have to set in the Editor.

Currently, I have to move a gameObject where I want my enemy to make a half-turn, copy the X position of the gameObject, and paste it in my enemy public variable.

Is there any easiest way to set coordinates in the editor?

I tried with ContextMenu but given the fact that Coroutines don’t run in editor mode, I don’t know how to get it to wait for mouse click.

    [ContextMenu ("SetX1")]
    void SetX1 () {
while (!Input.GetMouseButtonDown(0)) {
yield;
}
        print ("Mouse Clicked");
    }

Of course this doesn’t work since it’s a function and not a coroutine…

Thanks a lot in advance!

(Please forgive my english :slight_smile: )

I found the solution:

using UnityEngine;
using System.Collections;
using System.Reflection;
using UnityEditor;

[CustomEditor(typeof(testEditortoWorld))]
public class myEditor : Editor {
	private static bool m_editMode = false;
	private static bool m_editMode2 = false;
	
	void OnSceneGUI()
	{
		testEditortoWorld test = (testEditortoWorld)target;
		if (m_editMode)
		{
			if (Event.current.type == EventType.layout) {
				HandleUtility.AddDefaultControl(GUIUtility.GetControlID(GetHashCode(), FocusType.Passive));
			}
			if (Event.current.type == EventType.MouseDown)
			{
				Vector2 mousePos = Event.current.mousePosition;
				mousePos.y = Camera.current.pixelHeight - mousePos.y;
				Vector3 position = Camera.current.ScreenPointToRay(mousePos).origin;
				test.bord1X = position.x;
				m_editMode = false;
			}
			Event.current.Use();
		}
		if (m_editMode2)
		{
			if (Event.current.type == EventType.layout) {
				HandleUtility.AddDefaultControl(GUIUtility.GetControlID(GetHashCode(), FocusType.Passive));
			}
			if (Event.current.type == EventType.MouseDown)
			{
				Vector2 mousePos = Event.current.mousePosition;
				mousePos.y = Camera.current.pixelHeight - mousePos.y;
				Vector3 position = Camera.current.ScreenPointToRay(mousePos).origin;
				test.bord2X = position.x;
				m_editMode2 = false;
			}
			Event.current.Use();
		}
		
	}
	public override void OnInspectorGUI()
	{
		DrawDefaultInspector ();
		GUILayout.BeginHorizontal ("box");
			if (m_editMode)
		{
			if (GUILayout.Button("stopen",GUILayout.Width(60)))
			{
				m_editMode = false;
			}
		}
		else
		{
			if (GUILayout.Button("EditX1",GUILayout.Width(60)))
			{
				m_editMode = true;
				m_editMode2 = false;
			}
		}
		if (m_editMode2)
		{
			if (GUILayout.Button("stopen",GUILayout.Width(60)))
			{
				m_editMode2 = false;
			}
		}
		else
		{
			if (GUILayout.Button("EditX2",GUILayout.Width(60)))
			{
				m_editMode2 = true;
				m_editMode = false;
			}
		}
		GUILayout.EndHorizontal();
	}
}

testEditortoWorld being my enemyScript and bord1X and bord2X the coordinates variables