ExUnityMoveCodeC#
ExUnityMoveCodeC#
Collections;
using System.Collections.Generic;
using System.Linq.Expressions;
using Unity.Burst.CompilerServices;
using UnityEngine;
Rigidbody2D rb;
Animator anim;
SpriteRenderer spR;
BoxCollider2D bxC2D;
void Start()
{
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
spR = GetComponent<SpriteRenderer>();
bxC2D = GetComponent<BoxCollider2D>();
}
void Jump()
{
if(Input.GetButton("Jump"))
{
if(!isJumping)
{
rb.AddForce(new Vector2(0f, jumpForce), ForceMode2D.Impulse);
}
}
if(rb.velocity.y > jumpForce)
{
rb.velocity = rb.velocity.normalized * jumpForce;
}
if(isGrounded())
{
isJumping = false;
}
else
{
isJumping = true;
}
}
private bool isGrounded()
{
RaycastHit2D ground = Physics2D.BoxCast(bxC2D.bounds.center,
bxC2D.bounds.size, 0, Vector2.down, 0.1f, layerGround);
return ground.collider !=null;
}
}