Advertisement
tomicz

Untitled

Jul 1st, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PlayerController : MonoBehaviour {
  5.  
  6. public float jumpHeight;
  7. private bool jumpClicked;
  8. public Transform groundCheck;
  9. public LayerMask whatIsGround;
  10. public float groundCheckRadius;
  11. private bool grounded;
  12. private AudioSource audioSource;
  13. public AudioClip jumpSound;
  14.  
  15. // Use this for initialization
  16. void Start ()
  17. {
  18. audioSource = GetComponent<AudioSource>();
  19.  
  20.  
  21. }
  22.  
  23. // Update is called once per frame
  24. void Update ()
  25. {
  26. jumpBehavior();
  27. SlideBehavior();
  28.  
  29. }
  30.  
  31. void FixedUpdate()
  32. {
  33. grounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, whatIsGround);
  34.  
  35. }
  36.  
  37. private void jumpBehavior()
  38. {
  39. if (grounded)
  40. {
  41. audioSource.Play();
  42. if (Input.GetKeyDown(KeyCode.Space) || jumpClicked && grounded)
  43. {
  44. AudioSource.PlayClipAtPoint(jumpSound, transform.position);
  45. var accessAnimation = GetComponent<Animator>();
  46. var accessRigidBody = GetComponent<Rigidbody2D>();
  47. accessRigidBody.velocity = new Vector2(transform.position.x, jumpHeight);
  48. accessAnimation.SetTrigger("Jump");
  49. accessAnimation.SetTrigger("Land");
  50. jumpClicked = false;
  51. audioSource.Stop();
  52. }
  53.  
  54. }
  55.  
  56.  
  57. }
  58.  
  59. public void clickToJump()
  60. {
  61. jumpClicked = true;
  62. }
  63.  
  64. void SlideBehavior()
  65. {
  66. if (Input.GetKeyDown(KeyCode.S))
  67. {
  68. var accessAnimation = GetComponent<Animator>();
  69. accessAnimation.SetTrigger("Slide");
  70. accessAnimation.SetTrigger("Land");
  71. }
  72. }
  73.  
  74.  
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement