trying to rotate obj fixed degrees once

Hi,
I have now been digging into rotating objs for hours now… no breakthrough

Basically I want to rotate an obj (a disc) by 180 degrees around x, when I press on it.
I have a raytrace working and a control setting the disc to true to run my function
When the disc is true=pressed it turns blue (I did it for visual control of my code) and then it should ONLY rotate once by 180 degrees.
It turns blue but keeps rotating forever.
Can’t see what’s wrong with my for loop.
My code:

var i : int = 0;

function IconFeedbackFunction()
{
	
	for(i = 0; i < 20; i ++)
	{
		transform.Rotate(new Vector3(0+i, 0, 0));
		renderer.material.color = Color.blue;
		
		
		//transform.Rotate(Time.deltaTime * damp, Space.World);
		//var target = Vector3(0, 0, 0);
		//var rotate = Quaternion.LookRotation(target - transform.position);
		//transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);	
	}
}

Any pointers?
the commented lines are some of my attempts.

Not sure what the for loop is for. You should probably use Input.GetMouseButtonDown so you know your action only happens once per click. I don’t think a boolean is what you need for this. You set it to true, but do you set it to false shortly after? I’m guessing this is why it continues to rotate.

the loop was to make the obj rotate instead of just setting the value.
I will have more functionality running when my statement is true, so right now it is needed.
Pseudo: when something is one, I want the obj to rotate a fixed amount eventhough code might be running from Update()

See the Rotation function here.

–Eric

It’s not clear what’s going on. You should post how you are calling this function. I am gussing in the Update().

You can look at this thread for an example of flipping cards. Might be close to what you are after.
http://forum.unity3d.com/threads/69224-Rotation-woes-going-past-90deg-on-any-axis-forces-others-to-180-or-180-why

The for loop isn’t going to make it rotate like an animation. The for loop all happens on the same frame so any of the in-betweens will not be seen. You could try putting in a yield at the end like in the example Eric5h5 has linked to.

elveatles: How would you make the for loop then? I also though the syntax was right, but apparently the placing of the function wasn’t. :slight_smile:

I did not manage to make it work, but found iTween instead. Still annoyed by my lack of skills! :slight_smile: