# Move object while rotating another one

Hello. I am making something like old FM radio.

There is a wheel that can be rotated with mouse. Here is the code how I rotate it:

``````mouseClickPos = Input.mousePosition;
Vector3 dir = mouseClickPos - Camera.main.WorldToScreenPoint(transform.position);
angle-=90;
angle = Mathf.Round(angle/6.0f)*6.0f;
Quaternion q = Quaternion.AngleAxis(angle, Vector3.forward);
hand1.transform.rotation = Quaternion.RotateTowards(hand1.transform.rotation, q, 6);
``````

Now there is an arrow that needs to be moved on `y` axis from -4 to 4 when wheel is rotated. The arrow starts in 4, and when wheel is rotated to the right, arrow needs to go towards -4 point. And when it reaches -4, it needs to go back to 4 while wheel is rotated in same direction as from beginning. If player starts to rotate wheel to the other side (left), the arrow needs to start moving to the other side from the side it was going until then. I did try something like this but it is not working:

``````a1 = Mathf.Floor(oblaci.transform.localRotation.eulerAngles.z);
if(arrow.transform.localPosition.y >= 4.0f)
{
arrowUp = !arrowUp;
}
else if(arrow.transform.localPosition.y <= -4f)
{
arrowUp = !arrowUp;
}
if(a1>a2)
{
if(arrowUp)
{
arrow.transform.position = Vector3.Lerp(arrow.transform.position, new Vector3(arrow.transform.position.x, arrow.transform.position.y+0.0061111111f, arrow.transform.position.z), 1.0f);
}
else
{
arrow.transform.position = Vector3.Lerp(arrow.transform.position, new Vector3(arrow.transform.position.x, arrow.transform.position.y-0.0061111111f, arrow.transform.position.z), 1.0f);
}
}
else if(a1<a2)
{
if(arrowUp)
{
arrow.transform.position = Vector3.Lerp(arrow.transform.position, new Vector3(arrow.transform.position.x, arrow.transform.position.y-0.0061111111f, arrow.transform.position.z), 1.0f);
}
else
{
arrow.transform.position = Vector3.Lerp(arrow.transform.position, new Vector3(arrow.transform.position.x, arrow.transform.position.y+0.0061111111f, arrow.transform.position.z), 1.0f);
}
}
a2=a1;
``````

like this ?