diff --git a/Assets/Prefabs/Minion Icon.prefab b/Assets/Prefabs/Minion Icon.prefab index 03ced9a..120ee85 100644 --- a/Assets/Prefabs/Minion Icon.prefab +++ b/Assets/Prefabs/Minion Icon.prefab @@ -30,6 +30,7 @@ RectTransform: m_Children: - {fileID: 1979632679258755679} - {fileID: 1979632679604795358} + - {fileID: 4713540475464922574} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -51,6 +52,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: icon: {fileID: 1979632679604795359} + reloadSlider: {fileID: 5455234342035423124} indexInMinionList: 0 selectedColor: {r: 1, g: 1, b: 1, a: 1} unSelectedColor: {r: 0.6792453, g: 0.6792453, b: 0.6792453, a: 1} @@ -204,3 +206,166 @@ MonoBehaviour: m_FillOrigin: 0 m_UseSpriteMesh: 0 m_PixelsPerUnitMultiplier: 1 +--- !u!1 &2680926411192010905 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 4713540475464922574} + - component: {fileID: 5455234342035423124} + m_Layer: 5 + m_Name: Slider + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &4713540475464922574 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2680926411192010905} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 358338754108010580} + m_Father: {fileID: 1979632678310270258} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &5455234342035423124 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2680926411192010905} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 67db9e8f0e2ae9c40bc1e2b64352a6b4, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Navigation: + m_Mode: 3 + m_WrapAround: 0 + m_SelectOnUp: {fileID: 0} + m_SelectOnDown: {fileID: 0} + m_SelectOnLeft: {fileID: 0} + m_SelectOnRight: {fileID: 0} + m_Transition: 0 + m_Colors: + m_NormalColor: {r: 1, g: 1, b: 1, a: 1} + m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} + m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} + m_ColorMultiplier: 1 + m_FadeDuration: 0.1 + m_SpriteState: + m_HighlightedSprite: {fileID: 0} + m_PressedSprite: {fileID: 0} + m_SelectedSprite: {fileID: 0} + m_DisabledSprite: {fileID: 0} + m_AnimationTriggers: + m_NormalTrigger: Normal + m_HighlightedTrigger: Highlighted + m_PressedTrigger: Pressed + m_SelectedTrigger: Selected + m_DisabledTrigger: Disabled + m_Interactable: 1 + m_TargetGraphic: {fileID: 0} + m_FillRect: {fileID: 358338754108010580} + m_HandleRect: {fileID: 0} + m_Direction: 2 + m_MinValue: 0 + m_MaxValue: 1 + m_WholeNumbers: 0 + m_Value: 0.5 + m_OnValueChanged: + m_PersistentCalls: + m_Calls: [] +--- !u!1 &6604576339594320426 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 358338754108010580} + - component: {fileID: 6464480435457661666} + - component: {fileID: 6973380708449632018} + m_Layer: 5 + m_Name: Reload Fill + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &358338754108010580 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6604576339594320426} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 4713540475464922574} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!222 &6464480435457661666 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6604576339594320426} + m_CullTransparentMesh: 1 +--- !u!114 &6973380708449632018 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6604576339594320426} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 0.5188679, g: 0.5188679, b: 0.5188679, a: 0.4745098} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 0} + m_Type: 0 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 diff --git a/Assets/Scripts/MinionThrower.cs b/Assets/Scripts/MinionThrower.cs index 9f078fa..4065eba 100644 --- a/Assets/Scripts/MinionThrower.cs +++ b/Assets/Scripts/MinionThrower.cs @@ -11,8 +11,12 @@ public class MinionThrower : MonoBehaviour { bool isInThrowMode; Vector2 throwDirection = Vector2.right; MinionBar minionBar; + VampireEntity vampireEntity; + float currentCooldownTimer; + float currentInitialCooldown; void Awake() { + vampireEntity = GetComponent(); minionBar = FindObjectOfType(); aimArrow.SetActive(false); } @@ -23,6 +27,13 @@ public class MinionThrower : MonoBehaviour { } } + void FixedUpdate() { + if(currentCooldownTimer > 0f) { + currentCooldownTimer -= Time.fixedDeltaTime; + minionBar.UpdateReload(currentCooldownTimer / currentInitialCooldown); + } + } + public void ToggleThrowMode(InputAction.CallbackContext context) { if (context.performed) { isInThrowMode = true; @@ -40,9 +51,20 @@ public class MinionThrower : MonoBehaviour { } void PerformThrow() { - if (!isInThrowMode) { + if (!isInThrowMode || currentCooldownTimer > 0f) { return; } + + float minionHealthCost = 10f; // TODO + // if(minionHealthCost >= vampireEntity.Health) { + // return; + // } + vampireEntity.TakeDamage(minionHealthCost); + + currentInitialCooldown = 2f; // TODO + currentCooldownTimer = currentInitialCooldown; + minionBar.UpdateReload(currentCooldownTimer / currentInitialCooldown); + GameObject newMinion = Instantiate(minionBar.GetCurrentMinion(), transform.position + new Vector3(throwDirection.x, throwDirection.y, 0f) * 1f, Quaternion.identity); // Apply throw force } diff --git a/Assets/Scripts/UI/MinionBar.cs b/Assets/Scripts/UI/MinionBar.cs index 1dce358..d04da0b 100644 --- a/Assets/Scripts/UI/MinionBar.cs +++ b/Assets/Scripts/UI/MinionBar.cs @@ -5,9 +5,9 @@ using UnityEngine.InputSystem; public class MinionBar : MonoBehaviour { - List minionTypes; public GameObject minionIconPrefab; + List minionTypes; List minionIcons; int currentIndex; @@ -16,34 +16,26 @@ public class MinionBar : MonoBehaviour { minionIcons = new List(); } - // public void Start() { - // minionIcons = new List(); - // for (int i=0; i()); - // // minionIcons[i].icon = minionTypes.icon; // TODO - // minionIcons[i].indexInMinionList = i; - // minionIcons[i].UnSelect(); - // } - // minionIcons[currentIndex].Select(); - // } + void Start() { + UpdateReload(0f); + } public void ChangeSelectedIcon(InputAction.CallbackContext context) { - + float floatDelta = context.ReadValue(); int delta = 0; - if(floatDelta > 0.5f) { + if (floatDelta > 0.5f) { delta = 1; - } else if(floatDelta < -0.5f) { + } else if (floatDelta < -0.5f) { delta = -1; } minionIcons[currentIndex].UnSelect(); currentIndex += delta; - if(currentIndex >= minionIcons.Count) { + if (currentIndex >= minionIcons.Count) { currentIndex = 0; - } else if(currentIndex < 0) { + } else if (currentIndex < 0) { currentIndex = minionIcons.Count - 1; } @@ -57,13 +49,26 @@ public class MinionBar : MonoBehaviour { minionIcons.Add(newIcon); // minionIcons[i].icon = minionTypes.icon; // TODO newIcon.indexInMinionList = minionIcons.Count; - if(currentIndex == minionIcons.Count - 1) { + if (currentIndex == minionIcons.Count - 1) { newIcon.Select(); } else { newIcon.UnSelect(); } } + public void UpdateReload(float reloadFraction) { + float reloadFractionCorrected = reloadFraction; + if (reloadFractionCorrected < 0f) { + reloadFractionCorrected = 0f; + } else if (reloadFractionCorrected > 1f) { + reloadFractionCorrected = 1f; + } + + foreach (MinionIcon icon in minionIcons) { + icon.reloadSlider.value = reloadFractionCorrected; + } + } + public GameObject GetCurrentMinion() { return minionTypes[currentIndex]; } diff --git a/Assets/Scripts/UI/MinionIcon.cs b/Assets/Scripts/UI/MinionIcon.cs index 97c66fc..014a3cf 100644 --- a/Assets/Scripts/UI/MinionIcon.cs +++ b/Assets/Scripts/UI/MinionIcon.cs @@ -6,6 +6,7 @@ using UnityEngine.UI; public class MinionIcon : MonoBehaviour { public Image icon; + public Slider reloadSlider; [HideInInspector] public int indexInMinionList; public Color selectedColor; public Color unSelectedColor;