how to get real time mouse position (left / right) ???

am working on a small tank project were i have a moving tank now what am wanting to do is move my turret when i move my mouse left or right code below is what i currently have but it dont work so well can anyone help or show me a better way of detecting when mouse is going left or right ??

function Update () {
if (Input.mousePosition.y > 0) { //Rotate the turret to the right
    Debug.Log("Mouse is going Right");
    transform.Rotate(Vector3(0,rotationVel * Time.deltaTime,0));
} else if (Input.mousePosition.y < 0) { //Rotate the turret to the left
    Debug.Log("Mouse is Going Left");
    transform.Rotate(Vector3(0,-rotationVel * Time.deltaTime,0));
}

}

thank alot

There may be a better way to do this but I would do it like this

private var lastMousePosition : Vector2;
private var mouseDelta : Vector2;

function Start () {
    lastMousePosition = Input.mousePosition;
}

function Update () {
    mouseDelta = Input.mousePosition - lastMousePosition;
    lastMousePosition = Input.mousePosition;
    
    // now mouseDelta represents the change in position since the last frame
    if (mouseDelta.x > 0) {
        ...
    }
    else if (mouseDelta.x < 0) {
        ...
    }
}

thanks for fast reply that dont seam to work also when i move right it says moving right but when i move the mouse to the left it dont seam to pick it up right away thanks for the help :slight_smile: