Script that allows a player to rotate a game object using the left and right arrow keys. The object should rotate left when the left arrow is pressed and right when the right arrow is pressed.

using UnityEngine;

public class ObjectRotate : MonoBehaviour
{
    public float rotationSpeed = 90f;

    private void Update()
    {
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            transform.Rotate(Vector3.up, -rotationSpeed * Time.deltaTime);
        }
        if (Input.GetKey(KeyCode.RightArrow))
        {
            transform.Rotate(Vector3.up, rotationSpeed * Time.deltaTime);
        }
    }
}

Related Posts

Leave a Reply