You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.6 KiB
C#
54 lines
1.6 KiB
C#
3 weeks ago
|
using System.Collections;
|
||
|
using UnityEngine;
|
||
|
using Sirenix.OdinInspector;
|
||
|
using DG.Tweening;
|
||
|
|
||
|
public class attackTest : MonoBehaviour
|
||
|
{
|
||
|
public Animator animator = null;
|
||
|
public int AttackLayerIndex = 2;
|
||
|
public int AttackCount = 3;
|
||
|
private bool _canAttack = true;
|
||
|
private float _attackWeight = 0f;
|
||
|
private float _attackIdle = 0f;
|
||
|
private int _attackType = 0;
|
||
|
private IEnumerator _attackRoutine = null;
|
||
|
|
||
|
private void Awake() => _attackRoutine = AttackIdle();
|
||
|
|
||
|
void Update()
|
||
|
{
|
||
|
animator.SetLayerWeight(AttackLayerIndex, _attackWeight);
|
||
|
animator.SetFloat("Idle", _attackIdle);
|
||
|
}//Update() end
|
||
|
|
||
|
[Button]
|
||
|
public async void Attack()
|
||
|
{
|
||
|
if (_canAttack is false)
|
||
|
return;
|
||
|
|
||
|
StopCoroutine(_attackRoutine);
|
||
|
DOTween.Kill(_attackWeight);
|
||
|
_attackRoutine = AttackIdle();
|
||
|
StartCoroutine(_attackRoutine);
|
||
|
_canAttack = false;
|
||
|
_attackType = _attackType >= AttackCount ? 0 : _attackType;
|
||
|
animator.SetInteger("AttackType", _attackType);
|
||
|
animator.SetTrigger("Attack");
|
||
|
DOTween.To(()=> _attackWeight, x=> _attackWeight = x, 1f, 0.5f);
|
||
|
if(!await Tasks.Delay(0.8f)) return;
|
||
|
DOTween.To(()=> _attackWeight, x=> _attackWeight = x, 0f, 0.5f);
|
||
|
_attackType++;
|
||
|
_canAttack = true;
|
||
|
}//Attack() end
|
||
|
|
||
|
private IEnumerator AttackIdle()
|
||
|
{
|
||
|
DOTween.Kill(_attackIdle);
|
||
|
DOTween.To(()=> _attackIdle, x=> _attackIdle = x, 1f, 0.5f);
|
||
|
yield return new WaitForSeconds(5.0f);
|
||
|
DOTween.To(()=> _attackIdle, x=> _attackIdle = x, 0f, 0.5f);
|
||
|
}//Coroutine() end
|
||
|
}
|