Hello. My problem is not jumping when the character shoots and runs to the left. Without shooting, the character jumps normally, regardless of the side he is running. But when I shoot while running to the left, the character does not jump (to the right, everything works normally).please help
public float speed;
public float jumpForce;
public GameObject bulletPrefab;
public Transform shotSpawner;
private Animator anim;
private Rigidbody2D rb2d;
private bool facingRight = true;
private bool jump;
private float hForce = 0;
private bool onGround;
public Transform groundCheck;
public float checkRadius;
public LayerMask whatIsGround;
private bool lookingUp;
private bool lookingDown;
private float fireRate = 0.35f;
private float nextFire;
private bool isDead = false;
void Start()
{
rb2d = GetComponent();
anim = GetComponent();
}
void Update()
{
if (!isDead)
{
if (!onGround)
{
anim.SetBool(“Jump”, true);
}
if (onGround)
{
anim.SetBool(“Jump”, false);
}
if (Input.GetButtonDown(“Jump”) && onGround)
{
jump = true;
}
else if (Input.GetButtonUp(“Jump”))
{
if (rb2d.velocity.y > 0)
{
rb2d.velocity = new Vector2(rb2d.velocity.x, rb2d.velocity.y * 0.5f);
}
}
if (Input.GetButton(“Fire1”) && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
anim.SetBool(“Shoot”, true);
GameObject tempBullet = Instantiate(bulletPrefab, shotSpawner.position, shotSpawner.rotation);
if (!facingRight && !lookingUp)
{
tempBullet.transform.eulerAngles = new Vector3(0, 0, 180);
}
else if (!facingRight && lookingUp)
{
tempBullet.transform.eulerAngles = new Vector3(0, 0, 90);
}
if (!facingRight && lookingDown && hForce < 0)
{
tempBullet.transform.eulerAngles = new Vector3(0, 0, 205);
}
else if (!facingRight && lookingUp && hForce < 0)
{
tempBullet.transform.eulerAngles = new Vector3(0, 0, 155);
}
if (!onGround && lookingUp)
{
tempBullet.transform.eulerAngles = new Vector3(0, 0, 90);
}
else if (!onGround && lookingDown)
{
tempBullet.transform.eulerAngles = new Vector3(0, 0, -90);
}
}
if (Input.GetButtonUp(“Fire1”))
{
anim.SetBool(“Shoot”, false);
}
lookingUp = Input.GetButton(“Up”);
lookingDown = Input.GetButton(“Down”);
anim.SetBool(“LookingUp”, lookingUp);
anim.SetBool(“LookingDown”, lookingDown);
}
}
private void FixedUpdate()
{
if (!isDead)
{
onGround = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
hForce = Input.GetAxisRaw(“Horizontal”);
anim.SetFloat(“Speed”, Mathf.Abs(hForce));
rb2d.velocity = new Vector2(hForce * speed, rb2d.velocity.y);
if (hForce > 0 && !facingRight)
{
Flip();
}
else if (hForce < 0 && facingRight)
{
Flip();
}
if (jump)
{
anim.SetBool(“Jump”, true);
jump = false;
rb2d.AddForce(Vector2.up * jumpForce);
}
}
}
void Flip()
{
facingRight = !facingRight;
Vector3 scale = transform.localScale;
scale.x *= -1;
transform.localScale = scale;
}