Answer the question
In order to leave comments, you need to log in
Infinite jump I change the script, in theory the infinite jump should disappear, but the jump disappears altogether?
This is what the code looks like when the infinite jump works:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Jump : MonoBehaviour
{
Rigidbody2D rb;
public bool ReadyJump;
public bool ReadyGround;
public int ForceJump;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
if(ReadyJump == true)
{
rb.AddForce(new Vector2(0, ForceJump));
ReadyJump = false;
}
}
public void JumpPlayer()
{
ReadyJump = true;
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Ground")
{
ReadyGround = true;
}
else
{
ReadyGround = false;
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Jump : MonoBehaviour
{
Rigidbody2D rb;
public bool ReadyJump;
public bool ReadyGround;
public int ForceJump;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
if(ReadyJump && ReadyGround) // Изменено тут
{
rb.AddForce(new Vector2(0, ForceJump));
ReadyJump = false;
ReadyGround = false; // Изменено тут
}
}
public void JumpPlayer()
{
ReadyJump = true;
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Ground")
{
ReadyGround = true;
}
else
{
ReadyGround = false;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question