-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerAttackVisualAnimator.cs
More file actions
82 lines (68 loc) · 2.29 KB
/
Copy pathPlayerAttackVisualAnimator.cs
File metadata and controls
82 lines (68 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerAttackVisualAnimator : MonoBehaviour
{
//private bool attackInProgress = false;
//private float attackRange = 1.2f;
//[SerializeField] private LayerMask enemyLayer;
//private float damage = 7f;
//private Animator animator;
//private const string ATTACK = "Attack";
//private void Awake()
//{
// animator = GetComponent<Animator>();
//}
//private void Start()
//{
// Player.Instance.OnAttack += Player_OnAttack;
//}
//private void Player_OnAttack(object sender, EventArgs e)
//{
// attackInProgress = true;
// animator.SetTrigger(ATTACK);
//}
//private void Update()
//{
// if(attackInProgress && gameObject.activeSelf) {
// Collider[] enemiesHit = Physics.OverlapSphere(transform.position, attackRange, enemyLayer);
// foreach(Collider enemyCollider in enemiesHit) {
// if (!enemyCollider.gameObject.GetComponentInParent<Enemy>().ReturnIsDead())
// {
// enemyCollider.gameObject.GetComponentInParent<Enemy>().TakeDamage(damage);
// }
// }
// attackInProgress = false;
// }
//}
//private void OnDrawGizmosSelected()
//{
// Gizmos.DrawWireSphere(transform.position, attackRange);
//}
private bool isAttacking = false;
private float nextAttackWaitTime = 4f;
[SerializeField] GameObject attackVisual;
private float attackDuration = 3f;
private const string ATTACK_ANIMATION = "Attack";
private const string IDLE_ANIMATION = "Idle";
private void Update()
{
TriggerAttack();
}
private void TriggerAttack()
{
if (!isAttacking) { StartCoroutine(AttackRoutine()); }
}
private IEnumerator AttackRoutine()
{
isAttacking = true;
attackVisual.SetActive(true);
attackVisual.GetComponent<Animator>().SetTrigger(ATTACK_ANIMATION);
yield return new WaitForSeconds(attackDuration);
attackVisual.GetComponent<Animator>().SetTrigger(IDLE_ANIMATION);
attackVisual.SetActive(false);
yield return new WaitForSeconds(nextAttackWaitTime);
isAttacking = false;
}
}