- Home /
Object Rotation Sliders
So currently I have an object rotation script that is connected to sliders. Only problem is im not sure how to move it in one direction then make it go back to the original position based on where slider is, I probably will have to store max min and current but not sure how to implement:
public void W_KeyRotate(int wControl){
targetRotation *= Quaternion.Euler(mainCamera.transform.right * rotationAmount);
}
private void Snap()
{
Vector3 vec = targetRotation.eulerAngles;
vec.x = Mathf.Round(vec.x / rotationAmount) * rotationAmount;
vec.y = Mathf.Round(vec.y / rotationAmount) * rotationAmount;
vec.z = Mathf.Round(vec.z / rotationAmount) * rotationAmount;
targetRotation.eulerAngles = vec;
}
thats just part of the code
Comment
Well,
If I understand right you have 3 sliders and you would like that each of them control the rotation angle of the x/y/z axes.
and you want to rotate the camera?
Answer by termway · Apr 09, 2015 at 04:08 PM
If your sliders value is between 0 and 359, the code below should do the rotation of your object with slider value.
public Slider[] sliders = new Slider[3];//Put your sliders here
void Start()
{
sliders[0].value = transform.localEulerAngles.x;
sliders[1].value = transform.localEulerAngles.y;
sliders[2].value = transform.localEulerAngles.z;
foreach(Slider slider in sliders)
slider.onValueChanged.AddListener(Snap);
}
private void Snap(float value)
{
transform.localEulerAngles = new Vector3(
sliders[0].value,
sliders[1].value,
sliders[2].value
);
}