Как сделать разную силу прыжка в 2д платформере для телефона(UI кнопка)
Хочу реализовать разную силу прыжка для персонажа в 2д платформере на телефон. Вот мой код - void Update() { horizontal = Input.GetAxisRaw("Horizontal");
if (Input.GetButtonDown("Jump") && IsGrounded())
{
rb.velocity = new Vector2(rb.velocity.x, jumpingPower);
}
if (Input.GetButtonUp("Jump") && rb.velocity.y > 0f)
{
rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f);
}
if (Input.GetKey(KeyCode.A) && isRight == false)
{
Right();
}
if (Input.GetKey(KeyCode.D) && isRight == true)
{
Left();
}
}
public void OnJumpButtonDown()
{
if (IsGrounded())
{
rb.velocity = new Vector2(rb.velocity.x, jumpingPower);
}
if (rb.velocity.y > 0f)
{
rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f);
}
}
public void OnLeftButtonDown()
{
if(speed <= 0f)
{
speed = normalSpeed;
Left();
}
}
public void OnRightButtonDown()
{
if (speed >= 0f)
{
speed = -normalSpeed;
Right();
}
}
public void OnButtonUp()
{
speed = 0f;
}
private void FixedUpdate()
{
rb.velocity = new Vector2(speed, rb.velocity.y);
if (health > numOfHearts)
{
health = numOfHearts;
}
for (int i = 0; i < hearts.Length; i++)
{
if (i < Mathf.RoundToInt(health))
{
hearts[i].sprite = fullHeart;
}
else
{
hearts[i].sprite = emptyHearth;
}
if (i > numOfHearts)
{
hearts[i].enabled = true;
}
else
{
hearts[i].enabled = false;
}
}
}
private bool IsGrounded()
{
return Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer);
}