CakeMeister

PlayerAttack phan 16

Jul 13th, 2017
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 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.     public SoundManager sound;
  13.  
  14.     private void Awake()
  15.     {
  16.         anim = gameObject.GetComponent<Animator>();
  17.         trigger.enabled = false;
  18.         sound = GameObject.FindGameObjectWithTag("sound").GetComponent<SoundManager>();
  19.     }
  20.  
  21.    
  22.     // Update is called once per frame
  23.     void Update () {
  24.         if (Input.GetKeyDown(KeyCode.Z) && !attacking)
  25.         {
  26.             attacking = true;
  27.             trigger.enabled = true;
  28.             attackdelay = 0.3f;
  29.             sound.Playsound("sword");
  30.         }
  31.  
  32.         if (attacking)
  33.         {
  34.             if (attackdelay > 0)
  35.             {
  36.                 attackdelay -= Time.deltaTime;
  37.  
  38.             }
  39.             else
  40.             {
  41.                 attacking = false;
  42.                 trigger.enabled = false;
  43.             }
  44.         }
  45.  
  46.         anim.SetBool("Attacking", attacking);
  47.     }
  48. }
Add Comment
Please, Sign In to add comment