Sidescroll iphone rotate player

Hi I'm playing with the sidescroll setup for iPhone in the mobile assets.

I have put my character in the prefab and all is well, however I want the character to rotate or just switch 180 degrees when it changes direction (facing left or right).

in the sidescrollcontorl.js script I have added the two Rotate lines

if ( moveTouchPad.position.x > 0 ) { movement = Vector3.right * forwardSpeed * moveTouchPad.position.x; me.transform.Rotate( 0, 180, 0 ); } else{ movement = Vector3.right * backwardSpeed * moveTouchPad.position.x; me.transform.Rotate( 0, 0, 0 ); }

When I run it the character just flickers left and right I understand that this is been called with in the update function so its been told to rotate again and again.

anyhelp chaps

You should use Time.deltaTime:

if ( moveTouchPad.position.x > 0 )
{ 
movement = Vector3.right * forwardSpeed * moveTouchPad.position.x;
me.transform.Rotate( 0, 10 * Time.deltaTime, 0 );
}

 else{
 movement = Vector3.right * backwardSpeed * moveTouchPad.position.x;
 me.transform.Rotate( 0, 0, 0 );
}

This will rotate on the Y axis 10 degrees per second. You can change what you multiply Time.deltaTime by to increase the rotation speed e.g:

me.transform.Rotate( 0, 20 * Time.deltaTime, 0 )

rotates 20 degrees per second.