diff --git a/Assets/Player/Player.cs b/Assets/Player/Player.cs index 3763c81..3c03720 100644 --- a/Assets/Player/Player.cs +++ b/Assets/Player/Player.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.UI; public class Player : MonoBehaviour { @@ -34,6 +35,8 @@ private float maxHealth = 0; private float health = 0; + private float cooldownBaseScale = 1; + public GameObject MeshRoot; public enum PlayerState @@ -70,6 +73,8 @@ public GameObject PlayerMesh; + private Image attackCooldownImage; + private GameObject castLight; private float bottomOffset; public float BottomOffset { get { return bottomOffset; } } @@ -108,6 +113,12 @@ } } + cooldownBaseScale = uiHookup.AttackCooldown.localScale.x; + attackCooldownImage = uiHookup.AttackCooldown.GetComponentInChildren(); + + // scale to 0; + uiHookup.AttackCooldown.localScale = new Vector3(0, 0, 1); + //netItem.GetNetHost().SpawnItemLocal("test", // i => // { @@ -116,6 +127,9 @@ //); } + private float attackBuildup = 0; + private float attackCooldown = 0; + void TakeDamage(object detailsObj) { Dictionary details = detailsObj as Dictionary; @@ -127,6 +141,9 @@ { health = 0; // TODO die + + State = PlayerState.Dead; + netItem.DestroyItem(); } //Rect hRect = uiHookup.Health.rect; @@ -276,7 +293,7 @@ RectTransformUtility.ScreenPointToLocalPointInRectangle(uiHookup.AttackTouch, touch.position, null, out diff); if (diff.magnitude < radius && diff.magnitude > 0.2f) { - if (!wasInAttackTouch && State == PlayerState.Normal) + if (!wasInAttackTouch && State == PlayerState.Normal && attackCooldown == 0) { Attack(new Vector3(diff.x, 0, diff.y)); } @@ -315,9 +332,28 @@ } + if (attackCooldown > 0) + { + attackCooldownImage.color = new Color(1, 0, 0, 0.5f); + attackCooldown = Math.Max(0, attackCooldown - Time.deltaTime * AttackCooldownRate); + uiHookup.AttackCooldown.localScale = new Vector3(attackCooldown, attackCooldown, 1) * cooldownBaseScale; + } + else + { + attackCooldownImage.color = new Color(0, 0, 1, 0.5f); + attackBuildup = Math.Max(0, attackBuildup - Time.deltaTime * AttackBuildupRate); + uiHookup.AttackCooldown.localScale = new Vector3(attackBuildup, attackBuildup, 1) * cooldownBaseScale; + } + } } + + public float AttackBuildupStep = 0.2f; + + public float AttackBuildupRate = 1; + public float AttackCooldownRate = 0.5f; + private SimpleTween attackTween; public float AttackTime = 0.2f; @@ -333,6 +369,14 @@ private void Attack(Vector3 attackDir) { + attackBuildup += AttackBuildupStep; + if (attackBuildup > 1) + { + attackBuildup = 0; + attackCooldown = 1; + } + + State = PlayerState.Attacking; attackDelta = attackDir.normalized * AttackDist; diff --git a/Assets/Player/Player.cs b/Assets/Player/Player.cs index 3763c81..3c03720 100644 --- a/Assets/Player/Player.cs +++ b/Assets/Player/Player.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.UI; public class Player : MonoBehaviour { @@ -34,6 +35,8 @@ private float maxHealth = 0; private float health = 0; + private float cooldownBaseScale = 1; + public GameObject MeshRoot; public enum PlayerState @@ -70,6 +73,8 @@ public GameObject PlayerMesh; + private Image attackCooldownImage; + private GameObject castLight; private float bottomOffset; public float BottomOffset { get { return bottomOffset; } } @@ -108,6 +113,12 @@ } } + cooldownBaseScale = uiHookup.AttackCooldown.localScale.x; + attackCooldownImage = uiHookup.AttackCooldown.GetComponentInChildren(); + + // scale to 0; + uiHookup.AttackCooldown.localScale = new Vector3(0, 0, 1); + //netItem.GetNetHost().SpawnItemLocal("test", // i => // { @@ -116,6 +127,9 @@ //); } + private float attackBuildup = 0; + private float attackCooldown = 0; + void TakeDamage(object detailsObj) { Dictionary details = detailsObj as Dictionary; @@ -127,6 +141,9 @@ { health = 0; // TODO die + + State = PlayerState.Dead; + netItem.DestroyItem(); } //Rect hRect = uiHookup.Health.rect; @@ -276,7 +293,7 @@ RectTransformUtility.ScreenPointToLocalPointInRectangle(uiHookup.AttackTouch, touch.position, null, out diff); if (diff.magnitude < radius && diff.magnitude > 0.2f) { - if (!wasInAttackTouch && State == PlayerState.Normal) + if (!wasInAttackTouch && State == PlayerState.Normal && attackCooldown == 0) { Attack(new Vector3(diff.x, 0, diff.y)); } @@ -315,9 +332,28 @@ } + if (attackCooldown > 0) + { + attackCooldownImage.color = new Color(1, 0, 0, 0.5f); + attackCooldown = Math.Max(0, attackCooldown - Time.deltaTime * AttackCooldownRate); + uiHookup.AttackCooldown.localScale = new Vector3(attackCooldown, attackCooldown, 1) * cooldownBaseScale; + } + else + { + attackCooldownImage.color = new Color(0, 0, 1, 0.5f); + attackBuildup = Math.Max(0, attackBuildup - Time.deltaTime * AttackBuildupRate); + uiHookup.AttackCooldown.localScale = new Vector3(attackBuildup, attackBuildup, 1) * cooldownBaseScale; + } + } } + + public float AttackBuildupStep = 0.2f; + + public float AttackBuildupRate = 1; + public float AttackCooldownRate = 0.5f; + private SimpleTween attackTween; public float AttackTime = 0.2f; @@ -333,6 +369,14 @@ private void Attack(Vector3 attackDir) { + attackBuildup += AttackBuildupStep; + if (attackBuildup > 1) + { + attackBuildup = 0; + attackCooldown = 1; + } + + State = PlayerState.Attacking; attackDelta = attackDir.normalized * AttackDist; diff --git a/Assets/Player/Player.prefab b/Assets/Player/Player.prefab index 457b3f3..8799332 100644 --- a/Assets/Player/Player.prefab +++ b/Assets/Player/Player.prefab @@ -121,6 +121,9 @@ DefaultViewRadius: 4.8 CamFollowAmount: 0.9 SpotFollowAmount: 0.96 + AttackBuildupStep: 0.3 + AttackBuildupRate: 0.45 + AttackCooldownRate: 0.2 AttackTime: 0.2 AttackDist: 2 Damage: 1 diff --git a/Assets/Player/Player.cs b/Assets/Player/Player.cs index 3763c81..3c03720 100644 --- a/Assets/Player/Player.cs +++ b/Assets/Player/Player.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.UI; public class Player : MonoBehaviour { @@ -34,6 +35,8 @@ private float maxHealth = 0; private float health = 0; + private float cooldownBaseScale = 1; + public GameObject MeshRoot; public enum PlayerState @@ -70,6 +73,8 @@ public GameObject PlayerMesh; + private Image attackCooldownImage; + private GameObject castLight; private float bottomOffset; public float BottomOffset { get { return bottomOffset; } } @@ -108,6 +113,12 @@ } } + cooldownBaseScale = uiHookup.AttackCooldown.localScale.x; + attackCooldownImage = uiHookup.AttackCooldown.GetComponentInChildren(); + + // scale to 0; + uiHookup.AttackCooldown.localScale = new Vector3(0, 0, 1); + //netItem.GetNetHost().SpawnItemLocal("test", // i => // { @@ -116,6 +127,9 @@ //); } + private float attackBuildup = 0; + private float attackCooldown = 0; + void TakeDamage(object detailsObj) { Dictionary details = detailsObj as Dictionary; @@ -127,6 +141,9 @@ { health = 0; // TODO die + + State = PlayerState.Dead; + netItem.DestroyItem(); } //Rect hRect = uiHookup.Health.rect; @@ -276,7 +293,7 @@ RectTransformUtility.ScreenPointToLocalPointInRectangle(uiHookup.AttackTouch, touch.position, null, out diff); if (diff.magnitude < radius && diff.magnitude > 0.2f) { - if (!wasInAttackTouch && State == PlayerState.Normal) + if (!wasInAttackTouch && State == PlayerState.Normal && attackCooldown == 0) { Attack(new Vector3(diff.x, 0, diff.y)); } @@ -315,9 +332,28 @@ } + if (attackCooldown > 0) + { + attackCooldownImage.color = new Color(1, 0, 0, 0.5f); + attackCooldown = Math.Max(0, attackCooldown - Time.deltaTime * AttackCooldownRate); + uiHookup.AttackCooldown.localScale = new Vector3(attackCooldown, attackCooldown, 1) * cooldownBaseScale; + } + else + { + attackCooldownImage.color = new Color(0, 0, 1, 0.5f); + attackBuildup = Math.Max(0, attackBuildup - Time.deltaTime * AttackBuildupRate); + uiHookup.AttackCooldown.localScale = new Vector3(attackBuildup, attackBuildup, 1) * cooldownBaseScale; + } + } } + + public float AttackBuildupStep = 0.2f; + + public float AttackBuildupRate = 1; + public float AttackCooldownRate = 0.5f; + private SimpleTween attackTween; public float AttackTime = 0.2f; @@ -333,6 +369,14 @@ private void Attack(Vector3 attackDir) { + attackBuildup += AttackBuildupStep; + if (attackBuildup > 1) + { + attackBuildup = 0; + attackCooldown = 1; + } + + State = PlayerState.Attacking; attackDelta = attackDir.normalized * AttackDist; diff --git a/Assets/Player/Player.prefab b/Assets/Player/Player.prefab index 457b3f3..8799332 100644 --- a/Assets/Player/Player.prefab +++ b/Assets/Player/Player.prefab @@ -121,6 +121,9 @@ DefaultViewRadius: 4.8 CamFollowAmount: 0.9 SpotFollowAmount: 0.96 + AttackBuildupStep: 0.3 + AttackBuildupRate: 0.45 + AttackCooldownRate: 0.2 AttackTime: 0.2 AttackDist: 2 Damage: 1 diff --git a/Assets/Player/UIHookup.cs b/Assets/Player/UIHookup.cs index d5ad9a0..1ecbb23 100644 --- a/Assets/Player/UIHookup.cs +++ b/Assets/Player/UIHookup.cs @@ -8,6 +8,7 @@ public RectTransform AttackTouch; public Canvas MainCanvas; public RectTransform Health; + public RectTransform AttackCooldown; public float HealthWidth { get; set; } diff --git a/Assets/Player/Player.cs b/Assets/Player/Player.cs index 3763c81..3c03720 100644 --- a/Assets/Player/Player.cs +++ b/Assets/Player/Player.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.UI; public class Player : MonoBehaviour { @@ -34,6 +35,8 @@ private float maxHealth = 0; private float health = 0; + private float cooldownBaseScale = 1; + public GameObject MeshRoot; public enum PlayerState @@ -70,6 +73,8 @@ public GameObject PlayerMesh; + private Image attackCooldownImage; + private GameObject castLight; private float bottomOffset; public float BottomOffset { get { return bottomOffset; } } @@ -108,6 +113,12 @@ } } + cooldownBaseScale = uiHookup.AttackCooldown.localScale.x; + attackCooldownImage = uiHookup.AttackCooldown.GetComponentInChildren(); + + // scale to 0; + uiHookup.AttackCooldown.localScale = new Vector3(0, 0, 1); + //netItem.GetNetHost().SpawnItemLocal("test", // i => // { @@ -116,6 +127,9 @@ //); } + private float attackBuildup = 0; + private float attackCooldown = 0; + void TakeDamage(object detailsObj) { Dictionary details = detailsObj as Dictionary; @@ -127,6 +141,9 @@ { health = 0; // TODO die + + State = PlayerState.Dead; + netItem.DestroyItem(); } //Rect hRect = uiHookup.Health.rect; @@ -276,7 +293,7 @@ RectTransformUtility.ScreenPointToLocalPointInRectangle(uiHookup.AttackTouch, touch.position, null, out diff); if (diff.magnitude < radius && diff.magnitude > 0.2f) { - if (!wasInAttackTouch && State == PlayerState.Normal) + if (!wasInAttackTouch && State == PlayerState.Normal && attackCooldown == 0) { Attack(new Vector3(diff.x, 0, diff.y)); } @@ -315,9 +332,28 @@ } + if (attackCooldown > 0) + { + attackCooldownImage.color = new Color(1, 0, 0, 0.5f); + attackCooldown = Math.Max(0, attackCooldown - Time.deltaTime * AttackCooldownRate); + uiHookup.AttackCooldown.localScale = new Vector3(attackCooldown, attackCooldown, 1) * cooldownBaseScale; + } + else + { + attackCooldownImage.color = new Color(0, 0, 1, 0.5f); + attackBuildup = Math.Max(0, attackBuildup - Time.deltaTime * AttackBuildupRate); + uiHookup.AttackCooldown.localScale = new Vector3(attackBuildup, attackBuildup, 1) * cooldownBaseScale; + } + } } + + public float AttackBuildupStep = 0.2f; + + public float AttackBuildupRate = 1; + public float AttackCooldownRate = 0.5f; + private SimpleTween attackTween; public float AttackTime = 0.2f; @@ -333,6 +369,14 @@ private void Attack(Vector3 attackDir) { + attackBuildup += AttackBuildupStep; + if (attackBuildup > 1) + { + attackBuildup = 0; + attackCooldown = 1; + } + + State = PlayerState.Attacking; attackDelta = attackDir.normalized * AttackDist; diff --git a/Assets/Player/Player.prefab b/Assets/Player/Player.prefab index 457b3f3..8799332 100644 --- a/Assets/Player/Player.prefab +++ b/Assets/Player/Player.prefab @@ -121,6 +121,9 @@ DefaultViewRadius: 4.8 CamFollowAmount: 0.9 SpotFollowAmount: 0.96 + AttackBuildupStep: 0.3 + AttackBuildupRate: 0.45 + AttackCooldownRate: 0.2 AttackTime: 0.2 AttackDist: 2 Damage: 1 diff --git a/Assets/Player/UIHookup.cs b/Assets/Player/UIHookup.cs index d5ad9a0..1ecbb23 100644 --- a/Assets/Player/UIHookup.cs +++ b/Assets/Player/UIHookup.cs @@ -8,6 +8,7 @@ public RectTransform AttackTouch; public Canvas MainCanvas; public RectTransform Health; + public RectTransform AttackCooldown; public float HealthWidth { get; set; } diff --git a/Assets/Scenes/Lobby.unity b/Assets/Scenes/Lobby.unity index f05679c..7e9a49c 100644 --- a/Assets/Scenes/Lobby.unity +++ b/Assets/Scenes/Lobby.unity @@ -2336,6 +2336,79 @@ type: 3} m_PrefabInstance: {fileID: 1880450410} m_PrefabAsset: {fileID: 0} +--- !u!1 &1901356984 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1901356985} + - component: {fileID: 1901356987} + - component: {fileID: 1901356986} + m_Layer: 5 + m_Name: AttackCooldown + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1901356985 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1901356984} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1.7835172, y: 1.7835172, z: 1.7835172} + m_Children: [] + m_Father: {fileID: 2078452658} + m_RootOrder: 3 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 1, y: 0} + m_AnchorMax: {x: 1, y: 0} + m_AnchoredPosition: {x: -101, y: 96} + m_SizeDelta: {x: 100, y: 100} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1901356986 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1901356984} + 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, g: 0.13257027, b: 1, a: 0} + m_RaycastTarget: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 21300000, guid: e0dd069909c984f40996743021b53a62, type: 3} + 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 +--- !u!222 &1901356987 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1901356984} + m_CullTransparentMesh: 0 --- !u!1 &1917456049 GameObject: m_ObjectHideFlags: 0 @@ -2369,6 +2442,7 @@ AttackTouch: {fileID: 1086344764} MainCanvas: {fileID: 2078452657} Health: {fileID: 747122216} + AttackCooldown: {fileID: 1901356985} --- !u!4 &1917456052 Transform: m_ObjectHideFlags: 0 @@ -2761,6 +2835,7 @@ - {fileID: 747122216} - {fileID: 1731919963} - {fileID: 1086344764} + - {fileID: 1901356985} m_Father: {fileID: 0} m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/Player/Player.cs b/Assets/Player/Player.cs index 3763c81..3c03720 100644 --- a/Assets/Player/Player.cs +++ b/Assets/Player/Player.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.UI; public class Player : MonoBehaviour { @@ -34,6 +35,8 @@ private float maxHealth = 0; private float health = 0; + private float cooldownBaseScale = 1; + public GameObject MeshRoot; public enum PlayerState @@ -70,6 +73,8 @@ public GameObject PlayerMesh; + private Image attackCooldownImage; + private GameObject castLight; private float bottomOffset; public float BottomOffset { get { return bottomOffset; } } @@ -108,6 +113,12 @@ } } + cooldownBaseScale = uiHookup.AttackCooldown.localScale.x; + attackCooldownImage = uiHookup.AttackCooldown.GetComponentInChildren(); + + // scale to 0; + uiHookup.AttackCooldown.localScale = new Vector3(0, 0, 1); + //netItem.GetNetHost().SpawnItemLocal("test", // i => // { @@ -116,6 +127,9 @@ //); } + private float attackBuildup = 0; + private float attackCooldown = 0; + void TakeDamage(object detailsObj) { Dictionary details = detailsObj as Dictionary; @@ -127,6 +141,9 @@ { health = 0; // TODO die + + State = PlayerState.Dead; + netItem.DestroyItem(); } //Rect hRect = uiHookup.Health.rect; @@ -276,7 +293,7 @@ RectTransformUtility.ScreenPointToLocalPointInRectangle(uiHookup.AttackTouch, touch.position, null, out diff); if (diff.magnitude < radius && diff.magnitude > 0.2f) { - if (!wasInAttackTouch && State == PlayerState.Normal) + if (!wasInAttackTouch && State == PlayerState.Normal && attackCooldown == 0) { Attack(new Vector3(diff.x, 0, diff.y)); } @@ -315,9 +332,28 @@ } + if (attackCooldown > 0) + { + attackCooldownImage.color = new Color(1, 0, 0, 0.5f); + attackCooldown = Math.Max(0, attackCooldown - Time.deltaTime * AttackCooldownRate); + uiHookup.AttackCooldown.localScale = new Vector3(attackCooldown, attackCooldown, 1) * cooldownBaseScale; + } + else + { + attackCooldownImage.color = new Color(0, 0, 1, 0.5f); + attackBuildup = Math.Max(0, attackBuildup - Time.deltaTime * AttackBuildupRate); + uiHookup.AttackCooldown.localScale = new Vector3(attackBuildup, attackBuildup, 1) * cooldownBaseScale; + } + } } + + public float AttackBuildupStep = 0.2f; + + public float AttackBuildupRate = 1; + public float AttackCooldownRate = 0.5f; + private SimpleTween attackTween; public float AttackTime = 0.2f; @@ -333,6 +369,14 @@ private void Attack(Vector3 attackDir) { + attackBuildup += AttackBuildupStep; + if (attackBuildup > 1) + { + attackBuildup = 0; + attackCooldown = 1; + } + + State = PlayerState.Attacking; attackDelta = attackDir.normalized * AttackDist; diff --git a/Assets/Player/Player.prefab b/Assets/Player/Player.prefab index 457b3f3..8799332 100644 --- a/Assets/Player/Player.prefab +++ b/Assets/Player/Player.prefab @@ -121,6 +121,9 @@ DefaultViewRadius: 4.8 CamFollowAmount: 0.9 SpotFollowAmount: 0.96 + AttackBuildupStep: 0.3 + AttackBuildupRate: 0.45 + AttackCooldownRate: 0.2 AttackTime: 0.2 AttackDist: 2 Damage: 1 diff --git a/Assets/Player/UIHookup.cs b/Assets/Player/UIHookup.cs index d5ad9a0..1ecbb23 100644 --- a/Assets/Player/UIHookup.cs +++ b/Assets/Player/UIHookup.cs @@ -8,6 +8,7 @@ public RectTransform AttackTouch; public Canvas MainCanvas; public RectTransform Health; + public RectTransform AttackCooldown; public float HealthWidth { get; set; } diff --git a/Assets/Scenes/Lobby.unity b/Assets/Scenes/Lobby.unity index f05679c..7e9a49c 100644 --- a/Assets/Scenes/Lobby.unity +++ b/Assets/Scenes/Lobby.unity @@ -2336,6 +2336,79 @@ type: 3} m_PrefabInstance: {fileID: 1880450410} m_PrefabAsset: {fileID: 0} +--- !u!1 &1901356984 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1901356985} + - component: {fileID: 1901356987} + - component: {fileID: 1901356986} + m_Layer: 5 + m_Name: AttackCooldown + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1901356985 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1901356984} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1.7835172, y: 1.7835172, z: 1.7835172} + m_Children: [] + m_Father: {fileID: 2078452658} + m_RootOrder: 3 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 1, y: 0} + m_AnchorMax: {x: 1, y: 0} + m_AnchoredPosition: {x: -101, y: 96} + m_SizeDelta: {x: 100, y: 100} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1901356986 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1901356984} + 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, g: 0.13257027, b: 1, a: 0} + m_RaycastTarget: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 21300000, guid: e0dd069909c984f40996743021b53a62, type: 3} + 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 +--- !u!222 &1901356987 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1901356984} + m_CullTransparentMesh: 0 --- !u!1 &1917456049 GameObject: m_ObjectHideFlags: 0 @@ -2369,6 +2442,7 @@ AttackTouch: {fileID: 1086344764} MainCanvas: {fileID: 2078452657} Health: {fileID: 747122216} + AttackCooldown: {fileID: 1901356985} --- !u!4 &1917456052 Transform: m_ObjectHideFlags: 0 @@ -2761,6 +2835,7 @@ - {fileID: 747122216} - {fileID: 1731919963} - {fileID: 1086344764} + - {fileID: 1901356985} m_Father: {fileID: 0} m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/UI/WhiteCircle.png b/Assets/UI/WhiteCircle.png new file mode 100644 index 0000000..8f5327e --- /dev/null +++ b/Assets/UI/WhiteCircle.png Binary files differ diff --git a/Assets/Player/Player.cs b/Assets/Player/Player.cs index 3763c81..3c03720 100644 --- a/Assets/Player/Player.cs +++ b/Assets/Player/Player.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.UI; public class Player : MonoBehaviour { @@ -34,6 +35,8 @@ private float maxHealth = 0; private float health = 0; + private float cooldownBaseScale = 1; + public GameObject MeshRoot; public enum PlayerState @@ -70,6 +73,8 @@ public GameObject PlayerMesh; + private Image attackCooldownImage; + private GameObject castLight; private float bottomOffset; public float BottomOffset { get { return bottomOffset; } } @@ -108,6 +113,12 @@ } } + cooldownBaseScale = uiHookup.AttackCooldown.localScale.x; + attackCooldownImage = uiHookup.AttackCooldown.GetComponentInChildren(); + + // scale to 0; + uiHookup.AttackCooldown.localScale = new Vector3(0, 0, 1); + //netItem.GetNetHost().SpawnItemLocal("test", // i => // { @@ -116,6 +127,9 @@ //); } + private float attackBuildup = 0; + private float attackCooldown = 0; + void TakeDamage(object detailsObj) { Dictionary details = detailsObj as Dictionary; @@ -127,6 +141,9 @@ { health = 0; // TODO die + + State = PlayerState.Dead; + netItem.DestroyItem(); } //Rect hRect = uiHookup.Health.rect; @@ -276,7 +293,7 @@ RectTransformUtility.ScreenPointToLocalPointInRectangle(uiHookup.AttackTouch, touch.position, null, out diff); if (diff.magnitude < radius && diff.magnitude > 0.2f) { - if (!wasInAttackTouch && State == PlayerState.Normal) + if (!wasInAttackTouch && State == PlayerState.Normal && attackCooldown == 0) { Attack(new Vector3(diff.x, 0, diff.y)); } @@ -315,9 +332,28 @@ } + if (attackCooldown > 0) + { + attackCooldownImage.color = new Color(1, 0, 0, 0.5f); + attackCooldown = Math.Max(0, attackCooldown - Time.deltaTime * AttackCooldownRate); + uiHookup.AttackCooldown.localScale = new Vector3(attackCooldown, attackCooldown, 1) * cooldownBaseScale; + } + else + { + attackCooldownImage.color = new Color(0, 0, 1, 0.5f); + attackBuildup = Math.Max(0, attackBuildup - Time.deltaTime * AttackBuildupRate); + uiHookup.AttackCooldown.localScale = new Vector3(attackBuildup, attackBuildup, 1) * cooldownBaseScale; + } + } } + + public float AttackBuildupStep = 0.2f; + + public float AttackBuildupRate = 1; + public float AttackCooldownRate = 0.5f; + private SimpleTween attackTween; public float AttackTime = 0.2f; @@ -333,6 +369,14 @@ private void Attack(Vector3 attackDir) { + attackBuildup += AttackBuildupStep; + if (attackBuildup > 1) + { + attackBuildup = 0; + attackCooldown = 1; + } + + State = PlayerState.Attacking; attackDelta = attackDir.normalized * AttackDist; diff --git a/Assets/Player/Player.prefab b/Assets/Player/Player.prefab index 457b3f3..8799332 100644 --- a/Assets/Player/Player.prefab +++ b/Assets/Player/Player.prefab @@ -121,6 +121,9 @@ DefaultViewRadius: 4.8 CamFollowAmount: 0.9 SpotFollowAmount: 0.96 + AttackBuildupStep: 0.3 + AttackBuildupRate: 0.45 + AttackCooldownRate: 0.2 AttackTime: 0.2 AttackDist: 2 Damage: 1 diff --git a/Assets/Player/UIHookup.cs b/Assets/Player/UIHookup.cs index d5ad9a0..1ecbb23 100644 --- a/Assets/Player/UIHookup.cs +++ b/Assets/Player/UIHookup.cs @@ -8,6 +8,7 @@ public RectTransform AttackTouch; public Canvas MainCanvas; public RectTransform Health; + public RectTransform AttackCooldown; public float HealthWidth { get; set; } diff --git a/Assets/Scenes/Lobby.unity b/Assets/Scenes/Lobby.unity index f05679c..7e9a49c 100644 --- a/Assets/Scenes/Lobby.unity +++ b/Assets/Scenes/Lobby.unity @@ -2336,6 +2336,79 @@ type: 3} m_PrefabInstance: {fileID: 1880450410} m_PrefabAsset: {fileID: 0} +--- !u!1 &1901356984 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1901356985} + - component: {fileID: 1901356987} + - component: {fileID: 1901356986} + m_Layer: 5 + m_Name: AttackCooldown + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1901356985 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1901356984} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1.7835172, y: 1.7835172, z: 1.7835172} + m_Children: [] + m_Father: {fileID: 2078452658} + m_RootOrder: 3 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 1, y: 0} + m_AnchorMax: {x: 1, y: 0} + m_AnchoredPosition: {x: -101, y: 96} + m_SizeDelta: {x: 100, y: 100} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1901356986 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1901356984} + 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, g: 0.13257027, b: 1, a: 0} + m_RaycastTarget: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 21300000, guid: e0dd069909c984f40996743021b53a62, type: 3} + 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 +--- !u!222 &1901356987 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1901356984} + m_CullTransparentMesh: 0 --- !u!1 &1917456049 GameObject: m_ObjectHideFlags: 0 @@ -2369,6 +2442,7 @@ AttackTouch: {fileID: 1086344764} MainCanvas: {fileID: 2078452657} Health: {fileID: 747122216} + AttackCooldown: {fileID: 1901356985} --- !u!4 &1917456052 Transform: m_ObjectHideFlags: 0 @@ -2761,6 +2835,7 @@ - {fileID: 747122216} - {fileID: 1731919963} - {fileID: 1086344764} + - {fileID: 1901356985} m_Father: {fileID: 0} m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/UI/WhiteCircle.png b/Assets/UI/WhiteCircle.png new file mode 100644 index 0000000..8f5327e --- /dev/null +++ b/Assets/UI/WhiteCircle.png Binary files differ diff --git a/Assets/UI/WhiteCircle.png.meta b/Assets/UI/WhiteCircle.png.meta new file mode 100644 index 0000000..8915244 --- /dev/null +++ b/Assets/UI/WhiteCircle.png.meta @@ -0,0 +1,127 @@ +fileFormatVersion: 2 +guid: e0dd069909c984f40996743021b53a62 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 10 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: -1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 1 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 5e97eb03825dee720800000000000000 + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: