rotating constantly

I have made this schript:

using UnityEngine;
using System.Collections;

public class Okretanje : MonoBehaviour
{	
	public float speed = 50f;



	void Update ()
	{
		if(Input.GetKeyDown(KeyCode.Space))
		{
			transform.Rotate(Vector3.left, speed * Time.deltaTime);
		}
		else
		{
			transform.Rotate(Vector3.right, speed * Time.deltaTime);
	}
}
}

It is working…It rotates object right constantly but when i press space it rotates object left only for split second and continues to rotate it right.

But i would like it to make object rotate both ways constantly.
Like when i press space it rotate object left constantly and when i press space again it rotate object in opposite direction constantly.
So i would actually like to make toggle(every time i press button it rotates to opposite direction).

Any help would be great since I’m very bad with code. :slight_smile:

Thank you in advance. :smiley:

Try this :

using UnityEngine;
using System.Collections;
 
public class Okretanje : MonoBehaviour
{   
    public float speed = 50f;
    private boolean turnRight = false;
 
    void Update ()
    {
        if(Input.GetKeyDown(KeyCode.Space))
        {
             if (turnRight)
             {
                  transform.Rotate(Vector3.left, speed * Time.deltaTime);
                  turnRight = false;
             }
             else
             {
                  transform.Rotate(Vector3.right, speed * Time.deltaTime);
                  turnRight = true;
             }
        }
    }
}