Here's a copy of my code...
I can't seem to figure what the problem is
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class KeyBoardMoves : MonoBehaviour
{
public float speed = 5.0f;
public float rotateSpeed = 20.0f;
public bool canNotMoveSideways = true;
void Update ()
{
Movement ();
}
void Movement()
{
if (Input.GetKey (KeyCode.UpArrow)) {
Debug.Log ("Up arrow is being pressed!");
this.transform.Translate (new Vector3 (0, speed * Time.deltaTime, 0));
}
else if (Input.GetKey (KeyCode.DownArrow)) {
Debug.Log ("Down arrow is being pressed!");
this.transform.Translate (new Vector3 (0, -speed * Time.deltaTime, 0));
}
if (Input.GetKey (KeyCode.LeftArrow)) {
if (canNotMoveSideways)
{
Debug.Log ("You are now rotating left.");
this.transform.Translate(new Vector3 (0, -rotateSpeed*Time.deltaTime, 0));
}
else
{
Debug.Log ("Left arrow is being pressed!");
this.transform.Translate (new Vector3 (-speed * Time.deltaTime, 0, 0));
}
}
else if (Input.GetKey (KeyCode.RightArrow))
{
if (canNotMoveSideways)
{
Debug.Log("You are now rotating right.");
this.transform.Translate (new Vector3 (0, rotateSpeed*Time.deltaTime, 0));
}
else
{
Debug.Log ("Right arrow is being pressed!");
this.transform.Translate (new Vector3 (speed * Time.deltaTime, 0, 0));
}
}
}
↧