I have an 11 * 11 grid. I simply want to move penguins left, right, up, and down using the WASD keys. Here’s my code:
using UnityEngine;
using System.Collections;
public class PenguinMovement : MonoBehaviour {
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.A))
{
transform.position = new Vector3(4,0,0) * Time.deltaTime;
Debug.Log(4);
}
else if(Input.GetKeyDown(KeyCode.D))
{
transform.position = new Vector3(-4,0,0) * Time.deltaTime;
Debug.Log(-4);
}
else if(Input.GetKeyDown(KeyCode.W))
{
transform.position = new Vector3(0,0,4) * Time.deltaTime;
Debug.Log(4);
}
else if(Input.GetKeyDown(KeyCode.S))
{
transform.position = new Vector3(0,0,-4) * Time.deltaTime;
Debug.Log(4);
}
}
}
Is transform.position not the right command? Any help is appreciated. Thank you for your time in advance.