Search Unity

GUI.horizontalslider and camera sensitivity script help

Discussion in 'Scripting' started by NoirKurosuKai, Jul 31, 2016.

  1. NoirKurosuKai

    NoirKurosuKai

    Joined:
    May 23, 2016
    Posts:
    20
    I want to make a simple mouse sensitivity slider but i dunno how to start. Can anyone help me fix this please? Do i have to access the "public float mousesensitivity = 5.0f;"? if so can anyone help me Thanks again! Also if possible can you guys provide the editted code as a whole kinda sorta still a noob sorry...

    I also get this error:
    Controller.cs(24,44): error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected

    Controller script:
    Code (CSharp):
    1.  
    2.  
    3. using UnityEngine;
    4. using System.Collections;
    5.  
    6. public class Controller : MonoBehaviour {
    7.  
    8.     public float movementspeed = 5.0f;
    9.     public float mousesensitivity = 5.0f;
    10.     public float jumpspeed = 20.0f;
    11.  
    12.     float  verticalRotation = 0;
    13.     public float updownrange = 60.0f;
    14.  
    15.     float VerticalVelocity = 0;
    16.  
    17.     // Use this for initialization
    18.     void Start () {
    19.         Screen.lockCursor = false;
    20.     }
    21.  
    22.     // Update is called once per frame
    23.  
    24.         void Update () {
    25.             CharacterController cc = GetComponent <CharacterController> ();
    26.   mousesensitivity = HSlider;
    27.     //Rotation
    28.         float rotleftright = Input.GetAxis("Mouse X") * mousesensitivity;
    29.             transform.Rotate (0, rotleftright, 0);
    30.  
    31.         verticalRotation -= Input.GetAxisRaw("Mouse Y") * mousesensitivity;
    32.             verticalRotation = Mathf.Clamp (verticalRotation,-updownrange ,updownrange);
    33.                 Camera.main.transform.localRotation = Quaternion.Euler (verticalRotation, 0, 0);
    34.  
    35.  
    36.     //Movement
    37.  
    38.  
    39.         float forwardspeed = Input.GetAxis("Vertical") * movementspeed ;
    40.         float sidespeed = Input.GetAxis("Horizontal") * movementspeed ;
    41.  
    42.         VerticalVelocity += Physics.gravity.y * Time.deltaTime;
    43.  
    44.  
    45.         Vector3 speed = new Vector3 (sidespeed, VerticalVelocity , forwardspeed );
    46.  
    47.         speed = transform.rotation * speed;
    48.  
    49.  
    50.  
    51.         cc.Move ( speed * Time.deltaTime );
    52.     }
    53. }
    54.  
    Horizontal Slider script:
    Code (CSharp):
    1.  
    2.  
    3. using UnityEngine;
    4. using System.Collections;
    5.  
    6.  
    7.  
    8. public class HSlider : MonoBehaviour {
    9.  
    10.     static float vSliderValue = 5.0f;
    11.  
    12.     void Update () {
    13.    
    14.     }
    15.     void OnGUI ()
    16.     {
    17.         vSliderValue = GUI.HorizontalSlider(new Rect(830,500,200,200), vSliderValue, 5.0f, 0.0f);
    18.     }
    19.  
    20. }
    21.  
    22.  
     
    Last edited: Jul 31, 2016
  2. NoirKurosuKai

    NoirKurosuKai

    Joined:
    May 23, 2016
    Posts:
    20
    no help huh :(
     
  3. NoirKurosuKai

    NoirKurosuKai

    Joined:
    May 23, 2016
    Posts:
    20
    Anyone? Please? I really need to fix this cause i'm gonna submit this game tomorrow...
     
  4. NoirKurosuKai

    NoirKurosuKai

    Joined:
    May 23, 2016
    Posts:
    20
    Still expecting help...:(
     
  5. TrickyHandz

    TrickyHandz

    Joined:
    Jul 23, 2010
    Posts:
    196
    You need to make sure you are referencing the variable within the class you are referencing and not the type itself. That is what the error code your received is saying. Change:
    Code (CSharp):
    1. mousesensitivity = HSlider
    to:
    Code (CSharp):
    1. mousesensitivity = HSlider.vSliderValue;
    That should relieve your errors and get things functioning as your code intends.
     
  6. NoirKurosuKai

    NoirKurosuKai

    Joined:
    May 23, 2016
    Posts:
    20
    Ok i'll try. Thanks for noticing my thread really appreciate your help man!

    EDIT: I tried changing it but it has an error in mono develop 'error CS00117: 'Hslider' does not contain a definition for 'vSliderValue' and when I run the game and change the slider nothing really changes in the sensitivity...
     
    Last edited: Aug 2, 2016
  7. TrickyHandz

    TrickyHandz

    Joined:
    Jul 23, 2010
    Posts:
    196
    Sorry for the initial oversight on my part with the variable definition. Make sure that you have vSliderValue marked as public so that it can be accessed outside of the HSlider class. Additionally, you might want to look at just moving your OnGUI() method from the HSlider class into the Controller class and manipulate the mousesensitivity variable directly from there. That way you aren't storing values that don't need really need to be there.
     
  8. NoirKurosuKai

    NoirKurosuKai

    Joined:
    May 23, 2016
    Posts:
    20
    Your a lifesaver man thanks really appreciate your help!! Finally works!!
     
    TrickyHandz likes this.