diff options
author | Neil Kollack <nkollack@gmail.com> | 2022-04-23 22:08:26 -0500 |
---|---|---|
committer | Neil Kollack <nkollack@gmail.com> | 2022-04-23 22:08:26 -0500 |
commit | baf39e0e05808aaf16d6f7f8910fcb1e8de1736c (patch) | |
tree | 7d1ce7cb59d485a19e17b7ab4d404e509eb04aaf /Assets/Scripts | |
parent | 6b35ba7c38a34360a8374c9c12c8b7b94c46ed47 (diff) |
fix: implement enemy jump, air whip, player fb
Diffstat (limited to 'Assets/Scripts')
-rw-r--r-- | Assets/Scripts/Actors/Enemy.cs | 27 | ||||
-rw-r--r-- | Assets/Scripts/Actors/Player.cs | 2 | ||||
-rw-r--r-- | Assets/Scripts/Cursor.cs | 15 | ||||
-rw-r--r-- | Assets/Scripts/Items/Whip.cs | 13 | ||||
-rw-r--r-- | Assets/Scripts/LevelController.cs | 1 |
5 files changed, 51 insertions, 7 deletions
diff --git a/Assets/Scripts/Actors/Enemy.cs b/Assets/Scripts/Actors/Enemy.cs index d7d699e..600fcaf 100644 --- a/Assets/Scripts/Actors/Enemy.cs +++ b/Assets/Scripts/Actors/Enemy.cs @@ -1,5 +1,6 @@ using UnityEngine; using System.Collections; +using UnityEngine.InputSystem; namespace MontanaJohns.Actors { @@ -10,12 +11,18 @@ namespace MontanaJohns.Actors protected float attackRate = 0.5f; protected float nextAttackTime = 0f; - bool playerSeen; + private bool playerSeen; + private PlayerInput playerInput; + private InputAction jump; protected override void Awake() { base.Awake(); player = GameObject.FindGameObjectWithTag("Player"); + playerInput = player.GetComponent<PlayerInput>(); + + jump = playerInput.currentActionMap.FindAction("Jump"); + jump.started += context => Jump(); } // Update is called once per frame @@ -59,6 +66,24 @@ namespace MontanaJohns.Actors } } + public override void Jump() + { + if (Physics2D.OverlapCircle(groundCheckPoint1.position, 0.2f, groundLayers) || Physics2D.OverlapCircle(groundCheckPoint2.position, 0.2f, groundLayers)) + { + jumpCount = stats.maxJumps; + hangCount = hangTime; + } + else + { + hangCount -= Time.deltaTime; + } + if (jumpCount > 0 && hangCount > 0f) + { + jumpCount--; + _rigidBody.AddForce(Vector2.up * stats.jumpForce); + } + } + private void OnCollisionEnter2D(Collision2D other) { if (other.gameObject.tag == "Projectile") diff --git a/Assets/Scripts/Actors/Player.cs b/Assets/Scripts/Actors/Player.cs index 8535a41..f4edeef 100644 --- a/Assets/Scripts/Actors/Player.cs +++ b/Assets/Scripts/Actors/Player.cs @@ -32,7 +32,7 @@ namespace MontanaJohns.Actors jump.started += context => Jump(); use.started += context => Use(); - attack.started += context => Fire(); + //attack.started += context => Fire(); cancel.started += context => Cancel(); } diff --git a/Assets/Scripts/Cursor.cs b/Assets/Scripts/Cursor.cs index 43b0ea6..be46246 100644 --- a/Assets/Scripts/Cursor.cs +++ b/Assets/Scripts/Cursor.cs @@ -8,17 +8,24 @@ public class Cursor : MonoBehaviour [SerializeField] private Texture2D cursorTexture; [SerializeField] private float disableDistance = 20f; - private CursorMode cursorMode = CursorMode.Auto; private Vector2 hotSpot = Vector2.zero; // Update is called once per frame - void Update() + private void Update() { Vector2 mousePos = Camera.main.ScreenToWorldPoint(Mouse.current.position.ReadValue()); float distance = Vector2.Distance(mousePos, gameObject.transform.position); if (distance > disableDistance) - UnityEngine.Cursor.SetCursor(cursorTexture, hotSpot, cursorMode); + SetCursor(cursorTexture, hotSpot); else - UnityEngine.Cursor.SetCursor(null, Vector2.zero, cursorMode); + SetCursor(null, hotSpot); + } + + private void SetCursor(Texture2D cursorTexture, Vector2 hotSpot) + { + if(Application.platform == RuntimePlatform.WebGLPlayer) + UnityEngine.Cursor.SetCursor(cursorTexture, hotSpot, CursorMode.ForceSoftware); + else + UnityEngine.Cursor.SetCursor(cursorTexture, hotSpot, CursorMode.Auto); } } diff --git a/Assets/Scripts/Items/Whip.cs b/Assets/Scripts/Items/Whip.cs index b482f8d..5e33043 100644 --- a/Assets/Scripts/Items/Whip.cs +++ b/Assets/Scripts/Items/Whip.cs @@ -50,6 +50,10 @@ namespace MontanaJohns.Items StartCoroutine(WhipSmack(collisionGameObject)); } } + else + { + StartCoroutine(WhipSmack(clickLocation)); + } return null; } else @@ -69,5 +73,14 @@ namespace MontanaJohns.Items Destroy(currentHook); ropeExists = false; } + + private IEnumerator WhipSmack(Vector2 location) + { + currentHook = Instantiate(hookNoSwing, location, Quaternion.identity); + FindObjectOfType<AudioManager>().Play("WhipSwoosh"); + yield return new WaitForSeconds(0.1f); + Destroy(currentHook); + ropeExists = false; + } } }
\ No newline at end of file diff --git a/Assets/Scripts/LevelController.cs b/Assets/Scripts/LevelController.cs index 7113fe8..d79bc3b 100644 --- a/Assets/Scripts/LevelController.cs +++ b/Assets/Scripts/LevelController.cs @@ -65,7 +65,6 @@ public class LevelController : MonoBehaviour { foreach (GameObject obj in gameObjects) { - PrefabUtility.RevertPrefabInstance(obj, InteractionMode.AutomatedAction); Instantiate(obj); } } |