- Home /
two OnMouseDowns are not working at a time.
two "OnMouseDowns" are not working at a time.hi to all, i'm working as unity trainee in Hyderabad. right now i'm doing horse game,in this game i have joystick to move horse and a jump button to jump horse. please give me an idea to work both at a time.
Answer by tanoshimi · Jun 12, 2015 at 01:11 PM
How good are your reactions? Unless you're pressing both buttons in exactly the same frame (i.e. within 1/60th of a second of each other if your game runs at 60FPS), then you're not going to get OnMouseDown events for both of them firing. I suspect you meant to use GetMouseButton, not GetMouseButtonDown.
yeah i use Get$$anonymous$$ouseButton(0), but no use both are not working at a time. in joystick script i am using bellow script
private var object : Transform; // The object we will move. private var offSet : Vector3; // The object's position relative to the mouse position. private var dist : float;
function Update () {
var ray=Camera.main.ScreenPointToRay(Input.mousePosition); // Gets the mouse position in the form of a ray.
if (Input.GetButton("Fire1")) { // If we click the mouse...
if (!object) { // And we are not currently moving an object...
var hit : RaycastHit;
if (Physics.Raycast(ray, hit,5)) { // Then see if an object is beneath us using raycasting.
if (hit.transform.name == "Tunnel-Trouble-btn_2") {
object = hit.transform; // If we hit an object then hold on to the object.
offSet = object.position-ray.origin; // This is so when you click on an object its center does not align with mouse position.
}
} /* if (Physics.Raycast(ray, hit, $$anonymous$$athf.Infinity) && (hit.collider.tag == "Draggable")) { // Then see if an object is beneath us using raycasting.
object = hit.transform; // If we hit an object then hold on to the object.
offSet = object.position-hit.point; // This is so when you click on an object its center does not align with mouse position.
dist = (ray.origin - hit.point).magnitude; // Distance to the object from ray origin.
}*/
}
}
else if (Input.GetButtonUp("Fire1")) {
object = null;
transform.localPosition.x=-0.25;
transform.localPosition.y=0.1;
transform.localPosition.z=-0.46; // Let go of the object.
}
if (object) {
object.position = ray.GetPoint(dist) + offSet; // Only move the object on a 2D plane.
}
}
yeah i used Get$$anonymous$$ouseButton. but there is no use. booth are not working at a time.