- Home /
Question by
NoirKurosuKai · Jul 31, 2016 at 12:18 PM ·
c#mouselookhorizontal-slider
Adjusting Mouse Sensitivity through GUI.HorizontalSlider (c#)
I have here a character controller script where bothe the movement and camera rotation are in one script. Can anyone help me fix this please? Do i have to access the "publicfloat 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...
Controller script:
using UnityEngine;
using System.Collections;
public class Controller : MonoBehaviour {
public float movementspeed = 5.0f;
public float mousesensitivity = 5.0f;
public float jumpspeed = 20.0f;
float verticalRotation = 0;
public float updownrange = 60.0f;
float VerticalVelocity = 0;
// Use this for initialization
void Start () {
Screen.lockCursor = false;
}
// Update is called once per frame
void Update () {
CharacterController cc = GetComponent <CharacterController> ();
//Rotation
float rotleftright = Input.GetAxis("Mouse X") * mousesensitivity;
transform.Rotate (0, rotleftright, 0);
verticalRotation -= Input.GetAxisRaw("Mouse Y") * mousesensitivity;
verticalRotation = Mathf.Clamp (verticalRotation,-updownrange ,updownrange);
Camera.main.transform.localRotation = Quaternion.Euler (verticalRotation, 0, 0);
//Movement
float forwardspeed = Input.GetAxis("Vertical") * movementspeed ;
float sidespeed = Input.GetAxis("Horizontal") * movementspeed ;
VerticalVelocity += Physics.gravity.y * Time.deltaTime;
Vector3 speed = new Vector3 (sidespeed, VerticalVelocity , forwardspeed );
speed = transform.rotation * speed;
cc.Move ( speed * Time.deltaTime );
}
}
Slider Script:
using UnityEngine;
using System.Collections;
public class HSlider : MonoBehaviour {
float hSliderValue = 5.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
OnGUI {
Rect slider = new Rect (50, 30, 100, 30);
hSliderValue = GUI.HorizontalSlider(slider,hSliderValue,1.0f,100.0f);
}
}
Comment
Answer by TerkMaker · Jul 18, 2017 at 01:29 PM
Hi, I solved the script, the only thing you have to do is to put the content of a OnGui inside a void, important not to do the OnGui void because it will fail, Here is the script solved:
using UnityEngine; using System.Collections;
public class HSlider : MonoBehaviour {
float hSliderValue = 5.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
public void Update () {
Rect slider = new Rect (50, 30, 100, 30);
hSliderValue = GUI.HorizontalSlider(slider,hSliderValue,1.0f,100.0f);
}
}