- Home /
how to set the slider to rotate an object between two degrees on the y axis
i wanna set the slider to rotate an object between -60 and 60 so i wrote this code but it didn't work (HELP)
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class rotateplayer : MonoBehaviour {
public Slider slider;
public GameObject Player;
public void Adjustrotate ()
{
Player.transform.Rotate(0, slider.value*Time.deltaTime, 0);
}
}
Answer by Hellium · Dec 16, 2018 at 09:50 AM
Use the following script
public class rotateplayer : MonoBehaviour
{
public Transform Player;
public void Adjustrotate ( float angle )
{
Player.Rotate(0, angle, 0);
}
}
Then, select the Slider, and in the onValueChanged
box, click on the +
symbol, drag & drop the object holding the rotateplayer
script, and select the rotateplayer > Adjustrotate (Dynamic)
function. Don't forget to set the min anx max value of the slider to (-60,60)
in the inspector
Your answer
Follow this Question
Related Questions
Using a Gui slider to rotate the character 1 Answer
How to rotate the planar region to alway face the camera? 2 Answers
How do we write a C# script to smoothly rotate objects based on Input.GetAxis("Mouse *")? 1 Answer
How I can change this command to my Keyboard? 1 Answer
How to get an object to turn around/flip at a certain point 2 Answers