Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Jump : MonoBehaviour
- {
- public string jumpButton = "Fire1";
- public float jumpPower = 10.0f;
- public Animator anim;
- public bool grounded = false;
- public float minJumpDelay = 0.5f;
- public Transform groundCheck;
- private float jumpTime = 0.0f;
- private bool jumped = false;
- void Start (){
- }
- void Update (){
- grounded = Physics2D.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Ground"));
- jumpTime -= Time.deltaTime;
- if(Input.GetButtonDown(jumpButton) && grounded)
- {
- jumped = true;
- grounded = false;
- }
- if (jumped == true) // check if jump is true
- jump();
- }
- void jump (){
- if (jumped == true) // double check jump is true
- anim.SetTrigger("Jump");
- rigidbody2D.AddForce(transform.up*jumpPower);
- jumpTime = minJumpDelay;
- anim.SetTrigger("Jump");
- rigidbody2D.AddForce(transform.up*jumpPower);
- jumpTime = minJumpDelay;
- if(grounded == false && jumpTime <= 0 && jumped)
- jumped = false;
- fall();
- }
- void land (){
- jumped = false;
- anim.SetTrigger("Land");
- grounded = true;
- }
- void fall (){
- {
- anim.SetTrigger("Fall");
- }
- if(grounded)
- {
- anim.SetTrigger("Fall_Land");
- if(grounded == false && jumpTime <= 0 && jumped)
- land();
- }
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement