Как ограничить количество прыжков до 2? Просто у меня получается много прыжков.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class hero : MonoBehaviour
{
Rigidbody2D rb;
Animator anim;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown(KeyCode.Space))
{
jump();
}
if (Input.GetAxis ("Horizontal") == 0)
{
anim.SetInteger("Temp", 1);
}
else
{
Flip();
anim.SetInteger("Temp", 2);
}
}
void Flip()
{
if (Input.GetAxis("Horizontal") < 0)
transform.localRotation = Quaternion.Euler(0, 0, 0);
if (Input.GetAxis("Horizontal") > 0)
transform.localRotation = Quaternion.Euler(0, 180, 0);
}
void FixedUpdate()
{
Vector2 movement = new Vector2(Input.GetAxis("Horizontal") * 5f, rb.velocity.y);
rb.velocity = movement;
}
void jump()
{
rb.AddForce(transform.up * 5f, ForceMode2D.Impulse);
}
}