I have a code to move the object up/down/let/right. But what if I want ro rotate it left/right with the keys A/D, not move?
using UnityEngine;
using System.Collections;
public class MoveSphere : MonoBehaviour {
public GameObject player;
public int speed = 5;
void Start ()
{
player = (GameObject)this.gameObject;
}
void Update ()
{
if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
player.transform.position += player.transform.forward * speed * Time.deltaTime;
else if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
player.transform.position -= player.transform.forward * speed * Time.deltaTime;
else if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
player.transform.position -= player.transform.right * speed * Time.deltaTime;
else if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
player.transform.position += player.transform.right * speed * Time.deltaTime;
}
}