Mam taki problem że jak przytrzymam przycisk poruszania się w np prawą stronę a postać napotka ścianę a ja będe dalej trzymał przycisk to postać będzie stała nieruchomo i nie będzie spadała puki nie puszczę klawisza lub ściana nie zniknie.
oto skrypt
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour {
//predkosc poruszania
public float moveSpeed;
//wysokosc skoku
public float jumpHeight;
public Transform groundCheck;
public float groundCheckRadius;
public LayerMask WhatIsGround;
private bool grouned;
public bool doubleJump;
// Start is called before the first frame update
void Start()
{
}
void FixedUpdate()
{
grouned = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, WhatIsGround);
}
// Update is called once per frame
void Update() {
if (grouned)
doubleJump = false;
if (Input.GetKeyDown(KeyCode.W) && grouned)
{
Jump();
}
if (Input.GetKeyDown(KeyCode.W) && !grouned && !doubleJump)
{
Jump();
doubleJump = true;
}
if (Input.GetKey(KeyCode.D))
{
GetComponent<Rigidbody2D>().velocity = new Vector2(moveSpeed, GetComponent<Rigidbody2D>().velocity.y);
}
if (Input.GetKey(KeyCode.A))
{
GetComponent<Rigidbody2D>().velocity = new Vector2(-moveSpeed, GetComponent<Rigidbody2D>().velocity.y);
}
}
void Jump()
{
GetComponent<Rigidbody2D>().velocity = new Vector2(0, jumpHeight);
}
}