# problem with object rotation

for the auxiliary UI Button, I visit this line of code, how can I make the object click on the button turn 75 degrees and when he press the button again it returns to its original coordinates, that is, 0, I can’t find how to do it

``````if (click_detail4_1 == true)
{
detail4_1.localRotation = Quaternion.RotateTowards(detail4_1.localRotation, Quaternion.Euler(new Vector3(0, 75, 0)), 40f * Time.deltaTime);

}
if (click_detail4_2 == true)
{
detail4_2.localRotation = Quaternion.RotateTowards(detail4_2.localRotation, Quaternion.Euler(new Vector3(0, -75, 0)), 40f * Time.deltaTime);
}
``````

You haven’t provided very much context. When is this code running? Every Update? What’s click_detail4_1? When is it set to true? If you can provide more of the code this will be easier to figure out.

``````using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;

public class mehanic : MonoBehaviour
{

public Transform detail4_1;
public Transform detail4_2;

private bool click_detail4_1;
private bool click_detail4_2;

{
click_detail4_1 = true;

}
{
click_detail4_2 = true;

}

void FixedUpdate()
{

if (click_detail4_1 == true)
{
detail4_1.localRotation = Quaternion.RotateTowards(detail4_1.localRotation, Quaternion.Euler(new Vector3(0, 75, 0)), 40f * Time.deltaTime);

}
if (click_detail4_2 == true)
{
detail4_2.localRotation = Quaternion.RotateTowards(detail4_2.localRotation, Quaternion.Euler(new Vector3(0, -75, 0)), 40f * Time.deltaTime);
}

}
``````

(I’m assuming TaskOnClickDetail4_1/2 are being called by buttons.) You don’t have anything that sets either click_detail to “false”, so there’s no way for it to know when you’re supposed to be returning to the original rotation. If you want it to toggle each time you press the button:

``````click_detail4_1 = !clickdetail4_1;
``````

That will make it stop moving towards the 75 degree rotation, but there’s nothing to make it start moving back to the original. You probably want to do something like this:

``````        if (click_detail4_1 == true)
{
detail4_1.localRotation = Quaternion.RotateTowards(detail4_1.localRotation, Quaternion.Euler(new Vector3(0, 75, 0)), 40f * Time.deltaTime);

}
else
{
detail4_1.localRotation = Quaternion.RotateTowards(detail4_1.localRotation, Quaternion.Euler(new Vector3(0, 0, 0)), 40f * Time.deltaTime);
}
``````
1 Like

thanks more that everything is clearly explained, I tried to use click_detail4_1 =! clickdetail4_1; earlier, but I just scored that I need to use another else, and this was my mistake