using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using KairoEngine.Core; using KairoEngine.Inventory; using KairoEngine.SFX; namespace KairoEngine.CharacterSystem { /// /// Action to move a character in a certain direction and speed. /// 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().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().particleSystemGroup; particleSystem.SetActive(true); ParticleSystem[] systems = particleSystem.GetComponentsInChildren(); foreach (var system in systems) { system.loop = true; system.Play(); } handWeaponScript = weapon.GetComponent(); 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().enabled = false; ParticleSystem[] systems = particleSystem.GetComponentsInChildren(); foreach (var system in systems) { system.loop = false; } //if(handWeaponScript != null) handWeaponScript.damageTrigger.enabled = false; } public bool IsDone() { return done; } } }