From 9b7cd8f04db05a439a62ecd32b2c2d8eeb2f455a Mon Sep 17 00:00:00 2001 From: haitem Date: Sat, 30 Jan 2021 16:40:42 +0100 Subject: [PATCH] Add dash in player powers --- Assets/Scenes/Filip.unity | 7 +++++- Assets/Scripts/PlayerManager.cs | 43 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/Assets/Scenes/Filip.unity b/Assets/Scenes/Filip.unity index 0f2d414..b9a7a68 100644 --- a/Assets/Scenes/Filip.unity +++ b/Assets/Scenes/Filip.unity @@ -318,6 +318,11 @@ PrefabInstance: propertyPath: m_Name value: Player objectReference: {fileID: 0} + - target: {fileID: 7094923891560833916, guid: e4d82994b58b7304b91c915c597b71f8, + type: 3} + propertyPath: dashTime + value: 0.2 + objectReference: {fileID: 0} - target: {fileID: 7094923891560833916, guid: e4d82994b58b7304b91c915c597b71f8, type: 3} propertyPath: activeAbility.Array.size @@ -326,7 +331,7 @@ PrefabInstance: - target: {fileID: 7094923891560833916, guid: e4d82994b58b7304b91c915c597b71f8, type: 3} propertyPath: activeAbility.Array.data[0] - value: 3 + value: 0 objectReference: {fileID: 0} - target: {fileID: 7094923891560833917, guid: e4d82994b58b7304b91c915c597b71f8, type: 3} diff --git a/Assets/Scripts/PlayerManager.cs b/Assets/Scripts/PlayerManager.cs index c964abd..2d022c2 100644 --- a/Assets/Scripts/PlayerManager.cs +++ b/Assets/Scripts/PlayerManager.cs @@ -20,6 +20,10 @@ public class PlayerManager : MonoBehaviour public List activeAbility = new List(); //without ability=0 or null, dubleJump = 1, push/pull = 2, dash = 3 private bool dubleJump = true; private GameObject pushPullObject; + public float dashPower = 40f; + public float dashTime = 0.2f; + private float actualDashTime; + private int dashButton; private bool startEating = false; @@ -86,6 +90,45 @@ public class PlayerManager : MonoBehaviour ); } } + else if (activeAbility.Count > 0 && activeAbility[0] == 3) + { + if (Input.GetKeyUp(KeyCode.D) || Input.GetKeyUp(KeyCode.A)) { + if (actualDashTime < Time.time) + { + if (Input.GetKeyUp(KeyCode.D)) + { + dashButton = 1; + } + else if (Input.GetKeyUp(KeyCode.A)) + { + dashButton = 2; + } + actualDashTime = Time.time + dashTime; + } + else + { + if (dashButton == 1 && Input.GetKeyUp(KeyCode.D)) { + rigidBody.AddForce( + (transform.right * dashPower * 10 * 5 * 1 * Time.deltaTime) + + (transform.up * 1 * 10 * Time.deltaTime), + ForceMode.VelocityChange + ); + dashButton = 0; + actualDashTime = Time.time - 1f; + } + else if (dashButton == 2 && Input.GetKeyUp(KeyCode.A)) + { + rigidBody.AddForce( + (transform.right * dashPower * 10 * 5 * -1 * Time.deltaTime) + + (transform.up * 1 * 10 * Time.deltaTime), + ForceMode.VelocityChange + ); + dashButton = 0; + actualDashTime = Time.time - 1f; + } + } + } + } } public GameObject GetPushPullObject()