Kann mir jemand sagen, warum das Skript nicht funktioniert ? Alles funktioniert, außer das Springen. Danke im Voraus!
Um es besser zu lesen: https://prnt.sc/kmvelm
public class Test5 : MonoBehaviour {
public float maxSpeed = 4;
public float jumpForce = 550;
public Transform groundCheck;
public LayerMask whatIsGround;
[HideInInspector]
public bool lookingRight = true;
private Rigidbody2D rb2d;
private Animator anim;
private bool isGrounded = false;
private bool jump = false;
// Use this for initialization
void Start ()
{
rb2d = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update ()
{
if (Input.GetButtonDown("Jump") && isGrounded)
jump = true;
}
private void FixedUpdate()
{
float hor = Input.GetAxis("Horizontal");
anim.SetFloat("Speed", Mathf.Abs(hor));
rb2d.velocity = new Vector2(hor * maxSpeed, rb2d.velocity.y);
isGrounded = Physics2D.OverlapCircle(groundCheck.position, 0, 0, 15F, whatIsGround);
anim.SetBool("IsGrounded", isGrounded);
if ((hor > 0 && !lookingRight) || (hor < 0 && lookingRight))
Flip();
if (jump)
{
rb2d.AddForce(new Vector2(0, jumpForce));
jump = false;
}
}
public void Flip()
{
lookingRight = !lookingRight;
Vector3 myScale = transform.localScale;
myScale.x *= -1;
transform.localScale = myScale;
}
}