I know this sounds ridiculously easy but I’m struggling from quite some time and can’t find anything on the internet right now. I want to store the rotation values of a child gameobject in a variable.
if you are just trying to store transform.rotation then use Quaternion. Vector3 is if you are converting a Quaternion to Euler angles (euler angles are x,y,z and a Quaternion is x,y,z,w)
Hi @Vunpac, let me ask you a question!
I created two sliders, one for tilt (Z) and yaw (Y), Both works great on their own, my problem is when I try to use them together. If I move the Yaw half way and then I move the Tilt, the object returns to its original position instead of storing the current position and adjusting from then on. Hope this makes sense… I was trying to use your script to store the current angle and I know my main problem is that I have no clue how to use the stored angle and use the sliders to add on top of that.
Here is what I have so far:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ObjectControl : MonoBehaviour {
public GameObject objectToRotate;
public Slider rotateSlider;
public Slider tiltSlider;
public Slider scaleSlider;
public Quaternion InitialRot;
void Start()
{
InitialRot = Quaternion.Euler(new Vector3(this.transform.localRotation.x, this.transform.localRotation.y, this.transform.localRotation.z));
}
public void RotateMyObject(float sliderValueR)
{
sliderValueR = rotateSlider.value;
objectToRotate.transform.rotation = Quaternion.Euler(0, InitialRot + sliderValueR * 360, 0);
}
public void TiltMyObject(float sliderValueT)
{
sliderValueT = tiltSlider.value;
objectToRotate.transform.rotation = Quaternion.Euler(0, 0, sliderValueT * 360);
}
public void ScaleMyObject(float sliderValueS)
{
Vector3 scale = objectToRotate.transform.localScale;
sliderValueS = scaleSlider.value;
objectToRotate.transform.localScale = new Vector3(sliderValueS, sliderValueS, sliderValueS);
}
}