Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerAttackScript : MonoBehaviour
- {
- public float attackRate;
- public bool attacking = false;
- private Animator anim;
- private PlayerMovementScript pMovement;
- float nextAttack;
- void Start ()
- {
- anim = GetComponent<Animator> ();
- pMovement = GetComponent<PlayerMovementScript> ();
- }
- void Update ()
- {
- if (Input.GetKeyDown (KeyCode.F) && Time.time > nextAttack && pMovement.grounded)
- {
- nextAttack = Time.time + attackRate;
- attacking = true;
- }
- else if (Input.GetKeyUp (KeyCode.F))
- {
- attacking = false;
- }
- }
- void FixedUpdate ()
- {
- anim.SetBool ("isAttacking", attacking);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement