I’m new at making games in unity, that’s why I need help.
So I encountered a issue, while writing code for my prefab store shelves, which I wanted to rotate 270 degrees. Turns out, that shelves do what they want, and I don’t know why. (I’ve checked inspector and in some of them rotation was 90, some 360 and some 270) (prefab was dragged into the scene and default rotation was 0)
{
public float wantedRotation;
// Start is called before the first frame update
void Start()
{
GameEvent.current.onActivateShelves += FirstRotate;
GameEvent.current.ActivateShelves();
wantedRotation = 0.0f;
}
// Update is called once per frame
void Update()
{
if (wantedRotation > 360.0f)
wantedRotation -= 360.0f;
if (transform.rotation.eulerAngles.z <= wantedRotation || transform.rotation.eulerAngles.z >= wantedRotation + 3.0f)
{
transform.Rotate(Vector3.forward * (36 * Time.deltaTime));
Debug.Log(transform.rotation.eulerAngles.z);
}
}
public void FirstRotate()
{
wantedRotation += 270;
}