using System.Collections; using System.Collections.Generic; using UnityEngine; using RootMotion.FinalIK; using RootMotion.Demos; using KairoEngine.Core; using KairoEngine.Inventory; namespace KairoEngine.CharacterSystem { public class SetAimIK : MonoBehaviour { public Transform weaponAimIK; public CharacterController character; public AimController aimController; public AimIK aimIK; public LimbIK limbIK; public SecondHandOnGun secondHandOnGun; private bool isRealoding = false; void OnEnable() { GenericEvents.StartListening(character.unique_name + "-Reloading", Reloading); GenericEvents.StartListening(character.unique_name + "-ReloadDone", ReloadDone); } void OnDisable() { GenericEvents.StopListening(character.unique_name + "-Reloading", Reloading); GenericEvents.StopListening(character.unique_name + "-ReloadDone", ReloadDone); } void Update() { if(weaponAimIK == null) { if(character.HasEquipedItem() && isRealoding == false) { if(character.GetEquipedItem().item.category == ItemType.firearm) { Firearm firearm = character.GetEquipedGameObject().GetComponent(); weaponAimIK = firearm.aim; aimIK.solver.transform = weaponAimIK; limbIK.solver.target = firearm.grip; aimIK.enabled = true; limbIK.enabled = true; return; } } aimIK.enabled = false; limbIK.enabled = false; } } private void Reloading() { //Debug.Log("Reloading"); isRealoding = true; weaponAimIK = null; secondHandOnGun.enabled = false; } private void ReloadDone() { //Debug.Log("Reloading Done"); isRealoding = false; if(secondHandOnGun == null) return; secondHandOnGun.enabled = true; } } }