unity 2d movement problem
When im using this code, my character starts moving left without pressing A key, how can I fix this?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerController : MonoBehaviour
{
public Rigidbody2D rb;
private void Update()
{
if (Input.GetKey(KeyCode.A));
{
rb.velocity = new Vector2(-5, 0);
}
}
} ,My movement code for unity2d project is not working, when i wrote this code to rigidbody2d it's moving left without i pressing A key, what should I do?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerController : MonoBehaviour
{
public Rigidbody2D rb;
private void Update()
{
if (Input.GetKey(KeyCode.A));
{
rb.velocity = new Vector2(-5, 0);
}
}
}
Your answer
Follow this Question
Related Questions
How to I get my 2d gameobject to move towards another gameobject when it is clicked? 0 Answers
2D AI movement 0 Answers
New Input System: 2D top-down RPG OnMouseDown(0) 'player move to mouse position' 0 Answers
[2D] How to stop 2 vectors from adding force on each other 0 Answers
I can't seem to rotate my character depending on what side he is running to (2D sidescroller) 0 Answers