]> git.lizzy.rs Git - SuperMouseAdventure.git/commitdiff
coyote time
authorKG0104 <76601263+KG0104@users.noreply.github.com>
Fri, 1 Oct 2021 12:16:03 +0000 (14:16 +0200)
committerKG0104 <76601263+KG0104@users.noreply.github.com>
Fri, 1 Oct 2021 12:16:03 +0000 (14:16 +0200)
2DGame/Assets/Scenes/(1) Green_Idyll/green_idyll_10.unity
2DGame/Assets/Scripts/Mouse/MouseController.cs

index 32cd1b02a4f6d556355e67c0a4f243a82def4247..aab80cf8a6219103274e8c15908a4f97ec173eb2 100644 (file)
@@ -2169,6 +2169,7 @@ MonoBehaviour:
   m_Name: 
   m_EditorClassIdentifier: 
   flashingTime: 0.3
+  invulnerable: 0
 --- !u!114 &243225413
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -12870,6 +12871,7 @@ MonoBehaviour:
   speed: 36
   jumpForce: 50
   jumptime: 0.5
+  coyoteTime: 0.1
   isGrounded: 0
   groundcheck: {fileID: 972365582}
   checkRadius: 0.5
@@ -27480,7 +27482,7 @@ MonoBehaviour:
   m_EditorClassIdentifier: 
   lastCheckpointPos: {x: 0, y: 0, z: 0}
   firstCheckpoint: {fileID: 936765971}
-  mouse: {fileID: 214740917}
+  mouse: {fileID: 1649732366}
   lastCheeseCount: 0
   isCheeseCoinCollected: 0
 --- !u!1 &1423339812
index cefb6ea479c40052b0af9af7d9afa62db4a0cd47..122ae8477929bec360e0d7e96ed4976cf2f2f26b 100644 (file)
@@ -13,7 +13,10 @@ public class MouseController : MonoBehaviour
     public float jumptime;
     private bool isJumping;
     private float moveInput;
+    public float coyoteTime;
+    private bool jumpAllowed;
 
+    [HideInInspector]
     public bool isGrounded;
     public Transform groundcheck;
     public float checkRadius;
@@ -44,14 +47,23 @@ public class MouseController : MonoBehaviour
     // Update is called once per frame
     void Update()
     {
-               if (isGrounded == true && Input.GetButtonDown("Jump"))
+        if (!isGrounded)
+        {
+            StartCoroutine(CoyoteTime());
+        }
+        else
+        {
+            jumpAllowed = true;
+        }
+
+               if (jumpAllowed && Input.GetButtonDown("Jump"))
         {
             isJumping = true;
             jumpTimeCounter = jumptime;
             rb.velocity = new Vector2(rb.velocity.x, jumpForce);
         }
 
-        if (Input.GetButton("Jump") && isJumping == true)
+        if (Input.GetButton("Jump") && isJumping)
         {
             if (jumpTimeCounter > 0)
             {
@@ -107,7 +119,7 @@ public class MouseController : MonoBehaviour
                                return true;
                }
 
-               return false;
+               return false; 
        }
 
     void FixedUpdate()
@@ -144,6 +156,12 @@ public class MouseController : MonoBehaviour
                }
     }
 
+    IEnumerator CoyoteTime()
+    {
+        yield return new WaitForSeconds(coyoteTime);
+        jumpAllowed = false;
+    }
+
     void ResetShoot()
     {
         isShooting = false;