Im trying to make a gizmo like thing that is at the position of a gameobject
and when i click it !Even if its behind another object! to do some code
and it being a billboard image like the gizmos
if you dont understand my question just leave a comment and ill try and explain it in even more detail.
Personally I think layers are a better way to handle this situation, but here is a script that uses RaycastAll(). Attach it to the object you want to detect the mouse click. It will detect the click even if it is hidden behind another collider.
#pragma strict
function Update () {
if (Input.GetMouseButtonDown(0)) {
var hits : RaycastHit[] = Physics.RaycastAll (Camera.main.ScreenPointToRay(Input.mousePosition));
for (var i = 0; i < hits.Length; i++) {
if (hits*.transform == transform) {*
-
Debug.Log("I've been hit");*
-
}*
-
}*
- }*
}
Just for anyone reading this trying to get the answer for making a billboard texture that is stuck to a game object like the gizmos in the scene view but you want them in the game view read this thread it tells you how to do it