So I’m kinda new to this whole unity thing. I’ve been programming in C# for a while now and usually in order for something to move I’d just do a little “_playerPosition.x += 5;” but I tried that in Unity and it doesn’t seem to work.
This is my current movement code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
Vector2 _playerPosition;
// Use this for initialization
void Start () {
_playerPosition = Vector2.zero;
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.W)) {
_playerPosition.y += 5f;
}
if (Input.GetKeyDown(KeyCode.S)) {
_playerPosition.y -= 5f;
}
if (Input.GetKeyDown(KeyCode.D)) {
_playerPosition.x += 5f;
}
if (Input.GetKeyDown(KeyCode.A)) {
_playerPosition.x -= 5f;
}
}
}