Advertisement
Guest User

More Scripts

a guest
Jan 18th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class EasyMove : MonoBehaviour {
  5.  
  6. public float Speed = 0f;
  7. public float MaxJumpTime = 2f;
  8. public float JumpForce;
  9. private float move = 0f;
  10. private float JumpTime = 0f;
  11. private bool CanJump;
  12.  
  13.  
  14. void Start () {
  15. JumpTime = MaxJumpTime;
  16. }
  17.  
  18.  
  19. void Update ()
  20. {
  21. if (!CanJump)
  22. JumpTime -= Time.deltaTime;
  23. if (JumpTime <= 0)
  24. {
  25. CanJump = true;
  26. JumpTime = MaxJumpTime;
  27. }
  28. }
  29.  
  30. void FixedUpdate () {
  31. move = Input.GetAxis ("Horizontal");
  32. rigidbody2D.velocity = new Vector2 (move * Speed, rigidbody2D.velocity.y);
  33. if (Input.GetKey (KeyCode.W) && CanJump)
  34. {
  35. rigidbody2D.AddForce (new Vector2 (rigidbody2D.velocity.x,JumpForce));
  36. CanJump = false;
  37. JumpTime = MaxJumpTime;
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement