I have a simple Sprite called Player that has the follow components (Transform, Sprite Renderer, Box Collider 2D, Rigidbody 2D, Player Controller Script). In my Player Controller script I want to update the player's position when a key is pressed.
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
Vector2 playerPos;
// Use this for initialization
void Start () {
playerPos = gameObject.transform.position;
}
// Update is called once per frame
void FixedUpdate () {
if (Input.GetKey("d")) {
playerPos = new Vector2(playerPos.x + 0.2f, playerPos.y);
}
}
}
This script is attached to my gameobject but whenever I press or hold down the 'd' key, nothing happens to the player. Does anyone know how to fix this?