Hi there ppl.
Im having some kind of problem with using RayCast hits and Input.GetButton simultaneosly. Can you please help me ?
What i want to do is a mouse over in a normal gameobject, and a mouse click too in the same gameobject. I tried many things and searched a lot before i post this here, and actually i have this simple comparison :
function Update () {
var hit : RaycastHit;
if(Input.GetButtonDown("Fire1")) {
if(Physics.Raycast(Vector3(Input.mousePosition.x, Input.mousePosition.y, Input.mousePosition.z-200), transform.TransformDirection(Vector3.forward), hit, distance))
Debug.Log("Mouse DOWN " + hit.point);
}
}
I correctly get the debug log message saying where my mouse CLICKED …
and if i do this :
function Update () {
var hit : RaycastHit;
if (Physics.Raycast(Vector3(Input.mousePosition.x, Input.mousePosition.y, Input.mousePosition.z-200), transform.TransformDirection(Vector3.forward), hit, distance)) {
Debug.Log("Mouse OVER " + hit.point);
}
}
I correctly get the debug log message saying where my mouse IS MOVING. But instead, when i try to use both simultaneosly like this :
function Update () {
var hit : RaycastHit;
if (Physics.Raycast(Vector3(Input.mousePosition.x, Input.mousePosition.y, Input.mousePosition.z-200), transform.TransformDirection(Vector3.forward), hit, distance)) {
Debug.Log("Mouse OVER " + hit.point);
}
if(Input.GetButtonDown("Fire1")) {
if(Physics.Raycast(Vector3(Input.mousePosition.x, Input.mousePosition.y, Input.mousePosition.z-200), transform.TransformDirection(Vector3.forward), hit, distance))
Debug.Log("Mouse DOWN " + hit.point);
}
}
I only get the MOUSE OVER information and never get the information about the click!
Can you please help me understanding what m i doing wrong and whats the best way to achieve what i want ?
Thank you in advance.