Hello!
I made a custom editor to draw my levels for a game I am working on,
But I want to check if there is not already a tile where I want to click
private void OnSceneGUI()
{
HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));
_mousepos = Event.current.mousePosition;
if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
{
_tileParent = GameObject.Find("Level");
Ray ray = HandleUtility.GUIPointToWorldRay(_mousepos);
Debug.DrawRay(ray.origin, Vector3.forward* 100, Color.white, 4);
if (Physics.Raycast(ray.origin, new Vector3(0, 0, 100f), 1000f))
{
//doesnt work
if (_tileParent != null)
{
if (_currentTile != null)
{
int x = (int)Mathf.Round(ray.origin.x);
int y = (int)Mathf.Round(ray.origin.y);
GameObject clone = Instantiate(_currentTile, new Vector2(x, y), _currentTile.transform.rotation) as GameObject;
if (clone != null)
{
clone.transform.SetParent(_tileParent.transform);
}
}
}
}
}
}
I searched every where but it doesnt seem to work
can someone help me out please