Rotating Gameobject with (hidden) UI slider and Inputfield both positive and negativ

Hi there,

I got a new issue regarding my project, this time it’s split in different points:

I need to rotate a gameobject by a slider or slidefunction and inputfield around one axis.
Means if i use the slider, the value on the inputfield needs to change accordingly.

I also just want to see a button instead of a whole slider, so basically I’d need to press the button and then change the rotation by sliding left and right. Currently I just positioned the slider above the button which is not intereactable and set the alpha to 0, so it’s invisible, but maybe ther is another possibility to achieve this?

The other (and bigger issue) is, that I need the correct rotation in both positive and negative values but currently the object rotates just from 0° - 360° (I know that basically, this is right,as it transfers the negative angles from the negative space to a value from 0°-360°, but I NEED the values as put in in the inputfield or set by the slider for evaluation). Any idea how to manage this?

Thank you in advance!

best regards

Just assign a slider max value and min value. As for just wanting the button, create a gameobject>UI>Slider, on the slider delete the image component and delete the child fill area. You can tick use whole numbers on the slider if you don’t want floats.

Here,

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class SliderRotate : MonoBehaviour {

	public Slider slider;

	public float maxRotatePos;
	public float maxRotateNeg;
	public float currentRotation;

	void Awake()
	{
		//assign slider attributes

        if(maxRotatePos == 0)
		{
			maxRotatePos = 360;
		}
		if(maxRotateNeg == 0)
		{
			maxRotateNeg = -360;
		}

		slider.maxValue = maxRotatePos;
		slider.minValue = maxRotateNeg;
		currentRotation = 0;

	}


	// Update is called once per frame
	void Update () 
	{
		currentRotation = slider.value;
		transform.eulerAngles = new Vector3(0, currentRotation, 0);
	}
}

Steve.

Yes, and your script works well! I just need to be able to change the rotation of the object both with the slider or the inputfield. I linked the slider.value to the input.text, so if the slider.value changes it is shown on the inputfield. But if I want to type the rotation into the textfield, it doesn’t work out as I’d like it to.

I set the input.text to set slider.value if changed (slider.value = float.Parse(input.text), and set the Inputfield inspector to accept Decimal Numbers only.
But it’s having trouble when I try to type in a negative value…
I guess there is an issue with converting the string of the Inputfield to a float, is there any other option for this?
Also the Placeholder shows up everytime the Textfield is empty (even while still editing the text) and I can’t figure out how to reset the value of the Textfield as soon as I klick the Textfield (or: start Editing)…