Advertisement
Guest User

Untitled

a guest
Dec 27th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerAttackScript : MonoBehaviour
  6. {
  7. public float attackRate;
  8. public bool attacking = false;
  9.  
  10. private Animator anim;
  11. private PlayerMovementScript pMovement;
  12.  
  13. float nextAttack;
  14.  
  15. void Start ()
  16. {
  17. anim = GetComponent<Animator> ();
  18. pMovement = GetComponent<PlayerMovementScript> ();
  19. }
  20.  
  21. void Update ()
  22. {
  23. if (Input.GetKeyDown (KeyCode.F) && Time.time > nextAttack && pMovement.grounded)
  24. {
  25. nextAttack = Time.time + attackRate;
  26. attacking = true;
  27. }
  28. else if (Input.GetKeyUp (KeyCode.F))
  29. {
  30. attacking = false;
  31. }
  32. }
  33.  
  34. void FixedUpdate ()
  35. {
  36. anim.SetBool ("isAttacking", attacking);
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement