So, I’m working on a project for this year’s Halloween, and I decided on a Fantasy Zone-like game where you go up against a 5-10 minute boss.
Here’s the player code for the player:
public class Player : MonoBehaviour
{
public float playerdir;
public float dirrot;
public Vector2 direction = new Vector2(0, 1);
public bool moveUp;
public bool moveLeft; public bool moveRight;
public bool moveDown;
// Start is called before the first frame update
void Start()
{
Application.targetFrameRate = 30;
playerdir = 1;
}
// Update is called once per frame
void Update()
{
direction = (transform.localRotation * Vector2.right).normalized;
transform.rotation = Quaternion.Euler(0, -dirrot,0);
moveUp = Input.GetKey(KeyCode.W);
moveRight = Input.GetKey(KeyCode.D);
moveDown = Input.GetKey(KeyCode.S);
moveLeft = Input.GetKey(KeyCode.A);
if (playerdir == 1)
{
if (dirrot < 0)
{
dirrot += 12;
}
}
if (playerdir == -1)
{
if (dirrot > -180)
{
dirrot -= 12;
}
}
if (moveUp)
{
}
else if(moveDown)
{
}
if (moveRight)
{
playerdir = 1;
}
if (moveLeft)
{
playerdir = -1;
}
}
}
For some reason, I can press moveLeft while pressing moveRight and turn left, but not vice versa.
How can I make it so it works vice versa?