- Home /
Why OnMouseDrag is not being called?
I am new in unity, i just creted an scene with an object on it, i added a js script to this object.
First i was trying to print a message on cosole when the object was clicked, and i found out that there is an event like this:
function OnMouseDown (){}
i put it on my code after the update function and it never was called. Finnaly this worked for me:
if (Input.GetMouseButtonDown(0)) { Debug.Log("clicked"); }function Update () {
} Now i am trying to achieve the OnMouseDrag event, but it never gets called, why?
Answer by Landern · May 22, 2014 at 06:46 PM
They are not the same thing.
The event OnMouseDown is an event that is called when.. and i quote from the Documentation:
OnMouseDown is called when the user has pressed the mouse button while over the GUIElement or Collider.
If you haven't satisfied that event, the event will be not raised.
Update is called very frame, you are checking the Input for the mouse button to be down, and as long as it is during the frame, the if block is executed.
I had pressed the button over the object but it never fires the event
Answer by Bentoon · Jun 04, 2014 at 07:16 PM
For Future Ref This works:
var myFPS: Transform;
var someBoolean : boolean = false;
var camPos: Vector3;
var endPos: Vector3;
var time : float;
function Update () {
Debug.Log ("nope");
if(someBoolean == true) {
myFPS.transform.position.z = Mathf.Lerp(camera.main.transform.position.z, endPos.z, .5f * Time.deltaTime);
Debug.Log ("true");
//someBoolean = false;
}
}
function OnMouseUp () {
someBoolean = true;
Debug.Log ("setTrue");
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613145650im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Error BCE0044 JavaScript 1 Answer
Stopping a function when another function running. 2 Answers
Cube terrain with perlin noise 1 Answer