Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Mouse Sensitivity Slider Control: Stumped by C#. Javascript?

Discussion in 'Immediate Mode GUI (IMGUI)' started by AaronC, Apr 14, 2009.

  1. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Heya, Im looking for a way to use a gui slider to set the mouse sensitivity. If anyone has a snippet around maybe you'd share. I'd consider it a professional favor and would return it with some kind of art solution.

    The bundled Mouselook is C# thus confusing.
    Adapting the Mouselook plus from the wiki is also extra confusing.

    If anyone has a clue, and wants something in exchange, let me know? -Because I dont have a clue, lol.

    Thanks in advance
    AC
     
  2. Shaneo

    Shaneo

    Joined:
    Apr 2, 2009
    Posts:
    50
    Add this to the MouseLook script

    Code (csharp):
    1.  
    2.     void OnGUI()
    3.     {
    4.         sensitivityX = sensitivityY = GUI.HorizontalSlider( new Rect(0,0,200,50), sensitivityX, 1, 20 );
    5.     }
    6.  
    7.  
     
  3. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Thats great thanks.

    Look me up when you need some art of some kind.

    AaronC
     
  4. Carwash

    Carwash

    Joined:
    Nov 12, 2009
    Posts:
    95
    Sorry to revive an old thread, but it seemed better than starting a new one.

    Using the code posted above (thanks!) but it only seems to work for the X sensitivity. The Y sensitivity (up and down remains unaltered regardless of setting. Using the standard MouseLook script attached to the player object (set to mouse X) and its child main camera (set to mouseY).
    Any ideas?
     
  5. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Do you mean you are using the standard script with the suggested modifications, or two different versions of the script or... ?
     
  6. boxy

    boxy

    Joined:
    Aug 10, 2005
    Posts:
    675
    Ah this is what I've been looking for too in the hope it would compensate for some crazy magic mouse movement! :) In my case this works on the up down movement but not left to right. This is on the standard FP controller prefab, so both cam and capsule are using the same script. Does it matter where this snippet is placed in the script?
    TIA
    boxy
     
  7. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    If you don't have an existing OnGUI function in the script then just add it in. Otherwise, add the active line from the function body to the existing OnGUI function somewhere.
     
  8. boxy

    boxy

    Joined:
    Aug 10, 2005
    Posts:
    675
    Thanks Andeeee!
    I subsequently realised just that. Another small step. :)
    Cheers
     
  9. NoirKurosuKai

    NoirKurosuKai

    Joined:
    May 23, 2016
    Posts:
    20