using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
private Rigidbody2D rb2D;
private float moveSpeed;
private float jumpForce;
private bool isJumping;
float moveHorizontal;
float getKeyUp;
// Start is called before the first frame update
void Start()
{
rb2D = gameObject.GetComponent<Rigidbody2D>();
moveSpeed = 3f;
jumpForce = 60f;
isJumping = false;
}
// Update is called once per frame
void Update()
{
moveHorizontal = Input.GetAxisRaw("Horizontal");
getKeyUp = Input.GetKeyUp("Space");
}
void FixedUpdate()
{
if(moveHorizontal > 0.1f || moveHorizontal < -0.1f)
{
rb2D.AddForce(new Vector2(moveHorizontal * moveSpeed, 0f), ForceMode2D.Impulse);
}
if (!isJumping && getKeyUp > 0.1f)
{
rb2D.AddForce(new Vector2(0f, getKeyUp * jumpForce), ForceMode2D.Impulse);
}
}
void OnTriggerEnter2D(Collider2D collision)
{
if(collision.gameObject.tag == "Platform")
{
isJumping = false;
}
}
void OnTriggerExit2D(Collider2D collision)
{
if (collision.gameObject.tag == "Platform")
{
isJumping = true;
}
}
}
@Khada Please Help