Search Unity

MouseDrag() stops working

Discussion in 'Scripting' started by foq1978, Feb 11, 2010.

  1. foq1978

    foq1978

    Joined:
    Aug 5, 2009
    Posts:
    41
    I have the following piece of code attached to a cylinder, and it works fine, but every time I run it for some time (a matter of seconds), the On MouseDrag() stops working, not detecting my dragging. Any clues?

    Code (csharp):
    1.  
    2. static var strength : float;
    3. static var oldMouse: float;
    4.  
    5.    
    6.    function OnMouseDown() {
    7.    
    8.    oldMouse = Input.mousePosition.y;
    9.      
    10.    }
    11.      
    12.    function OnMouseDrag(){
    13.          
    14.    transform.Rotate( Vector3(strength,0,0) * Time.deltaTime );
    15.  
    16. }
    17. function Update () {
    18.    
    19.    strength = (Input.mousePosition.y - oldMouse);
    20.  
    21.  
    22.  
    23. }
    24.  
    25.  
    Thanks a lot!
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Does the dragging stop when the mouse moves off the object with the script?
     
  3. kevinatgame

    kevinatgame

    Joined:
    Aug 31, 2015
    Posts:
    8
    I just encountered the same problem. but I've not handled the mouse moving off the obj, I'll try and report here...