I cant move while jumping left or right and i dont know how to fix it
Here is my code:
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class Playermovement : MonoBehaviour
{
[SerializeField] GameObject Deathcontroll;
[SerializeField] Rigidbody2D rb;
[SerializeField] float jumppower;
[SerializeField] bool Canjump;
[SerializeField] float movepower;
[SerializeField] bool alive;
[SerializeField] bool Dpress;
[SerializeField] bool Apress;
private logiccontroller controller;
private bool spacedown;
// Start is called before the first frame update
private void Awake()
{
}
void Start()
{
rb = GetComponent<Rigidbody2D>();
alive = true;
controller = Deathcontroll.GetComponent<logiccontroller>();
}
// Update is called once per frame
void Update()
{
if (controller.isdead == true)
{
alive = false;
}
else
{
alive = true;
}
if (Input.GetKey(KeyCode.D))
{
Dpress = true;
}
else
{
Dpress = false;
}
if (Input.GetKey(KeyCode.A))
{
Apress = true;
}
else
{
Apress = false;
}
if (Input.GetKeyDown(KeyCode.Space))
{
spacedown = true;
}
else
{
spacedown = false;
}
if (Canjump == true && spacedown == true && alive == true)
{
rb.velocity = Vector2.up * jumppower;
controller.jumped = true;
}
else
{
controller.jumped = false;
}
if (Dpress == true && alive == true)
{
rb.velocity = Vector2.right * movepower;
}
if (Apress == true && alive == true)
{
rb.velocity = Vector2.left * movepower;
}
if (controller.reset == true)
{
gameObject.transform.position = new Vector3(0 , 0, 0);
}
}
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "grass")
{
Canjump = true;
Debug.Log("coldide");
}
}
void OnCollisionExit2D(Collision2D collision)
{
if (collision.gameObject.tag == "grass")
{
Canjump = false;
Debug.Log("not colided");
}
}
}