simple 360 degree Cube-rotation around y axis

Hi guys,

My Problem - i want to implement simple 360d. Cube -Rotation around Y-axis when i press the spacebar (so this Cube rotates itself only once when i press the spacebar and then stops) . How can i do this?

Heres my current code:

void Start () {

        mSpeed = 3f;
        RB = GetComponent<Rigidbody>();

    }

    // Update is called once per frame
    void Update () {
        transform.Translate(mSpeed*Input.GetAxis("Horizontal")*Time.deltaTime,0f,mSpeed*Input.GetAxis("Vertical")*Time.deltaTime);
        //transform.Rotate(Vector3.up, 100 * Time.deltaTime);

        if (Input.GetButtonDown ("Jump")) 
        {
            RB.velocity = new Vector3 (0,5,0);
        }

    }

Just do this:

void Update()
{
 if (Input.GetButtonDown ("Jump")) 
       transform.Rotate(Vector3.up * mSpeed * Time.deltaTime);
}

And if you want it to rotate while Space is pressed and stops when Space is released then just make

  if (Input.GetButton("Jump"))

Very roughly, maybe this can help you:

bool isRotAnimPlaying = false;
float mSpeed = 3f;
float currRot = 0f;
const float rotMax = 360f;
...
void Update ()
{
	// toggle rot anim state
	if(Input.GetButtonDown("Jump"))
	{
		isRotAnimPlaying = !isRotAnimPlaying; 
		// reset rot tracker to allow for new rot animation
		currRot = 0f; 
	}
		
	// play animation
	if(isRotAnimPlaying)
	{
		float step = mSpeed * Time.deltaTime;  
		// rotate object
		transform.Rotate(Vector3.up * step); 		
		// increment amount of rotation done
		currRot += step;
		
		// reached rot destination, stop animation
		if(currRot >= rotMax)
		{
			isRotAnimPlaying = false; 
			// reset rot tracker to allow for new rot animation
			currRot = 0f; 
		}
	}
}

It’s not precise in terms of 100% stop at 360 degrees, but it should get the desired effect you want.