Skip to content

Instantly share code, notes, and snippets.

@pr00thmatic
Created July 19, 2019 14:25
Show Gist options
  • Save pr00thmatic/2c15637847d30f20cf498de8712c4996 to your computer and use it in GitHub Desktop.
Save pr00thmatic/2c15637847d30f20cf498de8712c4996 to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
[CustomEditor(typeof(Prueba))]
public class PruebaEditor : Editor {
Prueba Target { get => (Prueba) target; }
void OnSceneGUI () {
Ray rayo = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
Debug.DrawLine(rayo.origin, rayo.origin + rayo.direction * 100);
RaycastHit hit;
Target.didHit = Physics.Raycast(rayo, out hit);
bool isClicking =
Event.current.type == EventType.MouseDown &&
Event.current.button == 0 ||
Event.current.type == EventType.MouseDrag;
if (Target.didHit && isClicking) {
GUIUtility.hotControl = GUIUtility.GetControlID(FocusType.Passive);
Event.current.Use();
Target.hitName = hit.collider.name;
Target.hitPoint.transform.position = hit.point;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment