How to rotate an object once?

Hi, I’m new and I still getting used to programming again.

We have a space ship which moves left, right, front, back with the arrows and we want it to move left and right and go 45º rotated when do it and go back to 0º when you stop clicking.

But what we have been able to do is to made it rotate 45º every time we clicked and even if we manage to made it back to 0º, the translation is with space ship axis (rotated 45º) instead the world axis.

I hope I explained myself fine, if not I can provide more info.

Thanks for the help.

=^^= =^^= =^^=

Problem auto solved/shot

Thanks for all the help and sorry for troubles.

The final code is like this

We have a file applied to the player (player_control)

var playerSpeed : float;
//var engineSound : GameObject;


function Start () {

}

function Update () {

	transform.Translate(Input.GetAxisRaw("Horizontal") * Time.deltaTime * playerSpeed, 0, Input.GetAxisRaw("Vertical") * Time.deltaTime * playerSpeed);
	
	
	transform.position.x = Mathf.Clamp(transform.position.x, -45, 45);
	transform.position.z = Mathf.Clamp(transform.position.z, -20, 20);

}

And a file aplied to the spaceship (player_angle)

function Start () {

}

function Update () {

	if(Input.GetKeyDown(KeyCode.RightArrow)) {

          transform.Rotate(Vector3(0.0, 30, 0.0));
    
    }
    
    else if (Input.GetKeyUp(KeyCode.RightArrow)) {

          transform.Rotate(Vector3(0.0, -30, 0.0));
    
    }
    
    if(Input.GetKeyDown(KeyCode.LeftArrow)) {

          transform.Rotate(Vector3(0.0, -30, 0.0));
    
    }
    
    else if (Input.GetKeyUp(KeyCode.LeftArrow)) {

          transform.Rotate(Vector3(0.0, 30, 0.0));
    
    }
    

}

So now the spaceship rotates, but don’t affect to the movement.

I’m not completely sure of what you are tying to do here. My biggest confusion is that the current movement code moves on the XZ plane, but your rotation code rotates on the ‘Z’ axis as if the movement should be on the XY plane. Here is a bit of sample code based on my best guess. It moves and rotates (for movement) based on the XY plane. If you want the XZ plane, let me know:

#pragma strict

var playerSpeed : float = 2.0;
 
function Update () {
    var angle = 0.0;
    if(Input.GetKey(KeyCode.RightArrow)) {
 
          if (Input.GetKey(KeyCode.LeftArrow))
          	 angle = 0.0;
          else
             angle = -45.0;
    }
 
    else if (Input.GetKey(KeyCode.LeftArrow)) {
         angle = 45;
    }
 
	transform.eulerAngles = Vector3(0.0, 0.0, angle);
	
    transform.Translate(Input.GetAxis("Vertical") * Time.deltaTime * playerSpeed * Vector3.up);

    transform.position.x = Mathf.Clamp(transform.position.x, -45, 45);
    transform.position.z = Mathf.Clamp(transform.position.z, -20, 20);
}

Best thing to do is a trigger on input.GetKeyUp, let’s say rotate when key pressed… When key not pressed rotate back to the original angle.