1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Events;
- using KairoEngine.Core;
- using KairoEngine.Inventory;
- using KairoEngine.SFX;
- namespace KairoEngine.CharacterSystem
- {
- /// <summary>
- /// Action to move a character in a certain direction and speed.
- /// </summary>
- public class CharacterHandWeaponAttackAction : IAction
- {
- CharacterController character; // Reference to the character that will move
- Vector3 targetPosition;
- bool done = false;
- GameObject particleSystem;
- HandWeapon handWeaponScript;
- // Constructor
- public CharacterHandWeaponAttackAction(CharacterController character, Vector3 targetPosition)
- {
- this.character = character;
- this.targetPosition = targetPosition;
- }
- public void Start()
- {
- character.animator.SetTrigger("Attack");
- character.rightHand.GetComponentInChildren<DamageEmitter>().enabled = true;
- GenericEvents.StartListening(character.unique_name + "-AnimationMeleeEnd", End);
- ItemRef itemRef = character.GetEquipedItem();
- ItemBaseHandWeapon handWeapon = (ItemBaseHandWeapon)itemRef.item;
- SoundController.EmmitSound(handWeapon.attackSound, targetPosition);
- GameObject weapon = character.GetEquipedGameObject();
- particleSystem = weapon.GetComponent<HandWeapon>().particleSystemGroup;
- particleSystem.SetActive(true);
- ParticleSystem[] systems = particleSystem.GetComponentsInChildren<ParticleSystem>();
- foreach (var system in systems)
- {
- system.loop = true;
- system.Play();
- }
- handWeaponScript = weapon.GetComponent<HandWeapon>();
- if(handWeaponScript != null) handWeaponScript.damageTrigger.enabled = true;
- }
- public void Update() { }
- public void End()
- {
- done = true;
- GenericEvents.StopListening(character.unique_name + "-AnimationMeleeEnd", End);
- character.rightHand.GetComponentInChildren<DamageEmitter>().enabled = false;
- ParticleSystem[] systems = particleSystem.GetComponentsInChildren<ParticleSystem>();
- foreach (var system in systems)
- {
- system.loop = false;
- }
- //if(handWeaponScript != null) handWeaponScript.damageTrigger.enabled = false;
- }
- public bool IsDone()
- {
- return done;
- }
- }
- }
|