Question by 
               unity_QTFZWi3erufDZw · Mar 26, 2020 at 07:11 PM · 
                rotationrotate objectrotatearoundrotate rotation  
              
 
              constant rotation using keypress
i want to rotate my object constantly when a key is pressed and lock it when the key is pressed again. How can I do? Thanks in advance :) This is my incorrect script
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class objectrotation : MonoBehaviour
 {
     public int speed;
      bool shouldRotate = false;
 
 
     // Update is called once per frame
     void Update()
     {
          if (Input.GetKeyDown(KeyCode.Space))
              {    
                 shouldRotate = !shouldRotate;
              }
 
          if (shouldRotate)
          {
            transform.Rotate (Vector3.up * Time.deltaTime * speed); 
          }
     
 }
 }
 
              
               Comment
              
 
               
              What does not work with your current script?
Are you sure you gave a value to the speed variable in the inspector? 
Your answer