Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Turn camera with mouse

Discussion in 'Scripting' started by b4guw1x, Jul 22, 2021.

  1. b4guw1x

    b4guw1x

    Joined:
    Apr 16, 2020
    Posts:
    12
    Hi. I got a small problem. I want to rotate my camera with mouse (Mouse X axis) . With joystick its easy because the Input.GetAxis doesn't return 0 while you pull the analog stick. But in mouse it's different because when you finish your drag movement, its returning 0. What i want to do is rotate camera as long as the mouse is on right edge or left edge. Anyone have an idea about it?
     
  2. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    Btw, if you get the mouse as an axis, it will still give you values even if the actual cursor doesn't move.
    But basically the code would look like this:

    Code (CSharp):
    1. if (Input.mousePosition.x < someThreshold) {
    2.     rotate here
    3. }
    And similarly for the other 3 edges
     
  3. b4guw1x

    b4guw1x

    Joined:
    Apr 16, 2020
    Posts:
    12
    thanks for your reply yeah i'm using a threshold value i meant aproximetly 0