Whenever I run this, Unity Freezes. I am pretty new to this skill. If you have any pointers on my code, or great ways to learn, I would love the input!
~Thanks.
The Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMove : MonoBehaviour
{
public float speed = 5f;
public Rigidbody2D rb;
private Vector2 Move;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
//This should give a number for moving the player with a key input to use on the function below
{
{
Move.x = 0; Move.y = 0;
}
while (Input.GetKeyDown("w"))
{
Move.y = 1;
}
while (Input.GetKeyDown("s"))
{
Move.y = -1;
}
while (Input.GetKeyDown("a"))
{
Move.x = -1;
}
while (Input.GetKeyDown("d"))
{
Move.x = 1;
}
}
void FixedUpdate()
//This is the function for the movement
{
rb.MovePosition(rb.position + Move * speed * Time.fixedDeltaTime);
}
}