CakeMeister

Player Attack phan 10

Jul 3rd, 2017
1,201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerAttack : MonoBehaviour {
  6.     public float attackdelay = 0.3f;
  7.     public bool attacking = false;
  8.  
  9.     public Animator anim;
  10.  
  11.     public Collider2D trigger;
  12.  
  13.     private void Awake()
  14.     {
  15.         anim = gameObject.GetComponent<Animator>();
  16.         trigger.enabled = false;
  17.     }
  18.  
  19.    
  20.     // Update is called once per frame
  21.     void Update () {
  22.         if (Input.GetKeyDown(KeyCode.Z) && !attacking)
  23.         {
  24.             attacking = true;
  25.             trigger.enabled = true;
  26.             attackdelay = 0.3f;
  27.         }
  28.  
  29.         if (attacking)
  30.         {
  31.             if (attackdelay > 0)
  32.             {
  33.                 attackdelay -= Time.deltaTime;
  34.  
  35.             }
  36.             else
  37.             {
  38.                 attacking = false;
  39.                 trigger.enabled = false;
  40.             }
  41.         }
  42.  
  43.         anim.SetBool("Attacking", attacking);
  44.     }
  45. }
Add Comment
Please, Sign In to add comment