I am following Jonathan Weinberger’s tutorial series, and on his first video he shows you how to make a cube move left/right/up/down.
This is the C# coding he uses to accomplish a left right movement.
transform.Translate (Vector3.right * Input.GetAxis (“Horizontal”));
The problem is, when I click play, the cube does not move when I press the arrow keys. Now, I’m not sure if this is due to a different version of Unity or not… I have 4.2.2. I am running a macbook pro. Arrow keys work fine with everything else, just not when I hit play and try to get the cube to move.
Here is the whole script I am using.
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
public float playerSpeed = 5.0f;
// Use this for initialization
void Start () {
//Player start position when games starts.
//Player at X,Y,Z
transform.position = new Vector3(1, 0, 0);
//player to move left/right/up/down
//player (gameobject) aka transform to move when I press arrow keys.
transform.Translate (Vector3.right * Input.GetAxis ("Horizontal") * playerSpeed * Time.deltaTime);
}
// Update is called once per frame
void Update () {
}
}