I can’t jump sometimes when i land in another platform after jump. I not 100% sure how to use the funtion void OnTriggerEnter2D():
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMove : MonoBehaviour {
public float MoveSpeed;
public float JumpVelocity;
private bool OnTheFloor;
private Rigidbody2D RBody;
// Use this for initialization
void Start () {
OnTheFloor = false;
RBody = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update() {
Movement();
}
void Movement() {
if (Input.GetKey(KeyCode.RightArrow))
{
RBody.velocity = new Vector2(MoveSpeed, RBody.velocity.y);
transform.eulerAngles = new Vector2(0, 0);
}
if (Input.GetKey(KeyCode.LeftArrow))
{
RBody.velocity = new Vector2(-MoveSpeed, RBody.velocity.y);
transform.eulerAngles = new Vector2(0, 180);
}
if (Input.GetKey(KeyCode.LeftArrow)==false && Input.GetKey(KeyCode.RightArrow) == false) {
RBody.velocity = new Vector2(0f, RBody.velocity.y);
}
if (Input.GetKey(KeyCode.Space) || Input.GetKey(KeyCode.UpArrow)) {
if (OnTheFloor)
{
RBody.velocity = new Vector2(RBody.velocity.x, JumpVelocity);
}
}
//evito que tenga velocidad cuando gira
RBody.angularVelocity = 0f;
}
void OnTriggerEnter2D()
{
OnTheFloor = true;
}
void OnTriggerExit2D()
{
OnTheFloor = false;
}
}