try to win (DONT LOSE)
A downloadable gg
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float moveSpeed = 5f;
public float jumpForce = 10f;
private Rigidbody2D rb;
private bool isGrounded;
private Animator anim;
void Start()
{
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
void Update()
{
float moveInput = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(moveInput * moveSpeed, rb.velocity.y);
if (moveInput != 0)
{
anim.SetBool("isRunning", true);
}
else
{
anim.SetBool("isRunning", false);
}
if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
{
rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
anim.SetTrigger("jump");
}
}
void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.CompareTag("Ground"))
{
isGrounded = true;
anim.SetBool("isJumping", false);
}
}
void OnCollisionExit2D(Collision2D other)
{
if (other.gameObject.CompareTag("Ground"))
{
isGrounded = false;
anim.SetBool("isJumping", true);
}
}
}
Status | Prototype |
Author | Mustii_POWER |
Genre | Action |
Tags | 2D |
Comments
Log in with itch.io to leave a comment.
WOW IT IS SO GOOD