Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
This question was closed Oct 28, 2015 at 08:35 AM by Joppix.
avatar image
0
Question by Joppix · Oct 14, 2015 at 01:28 PM · c#2dplayerrigidbody2djump

Problem with a multi-jump script ( C# )

As the title says, i have a problem with a script that should allow me make a multi-jump with a JumpCount wich is going to run out after 4 jumps and recharge when i touch the ground. The script does not give any error, but i think there is something wrong directly in the script's drawing up It simply doesen't work when i apply it, my character jumps just one time.

 using UnityEngine;
 using System.Collections;
 
 public class Volo : MonoBehaviour {
     float jumpCount;
     public Vector2 jumpForce = new Vector2(0, 300);
     bool grounded;
     void Update()
     {
         // If the character has more than 0 jumps left
         if (Input. GetKeyDown("space") && jumpCount > 0)
         {
             GetComponent<Rigidbody2D>().velocity = Vector2.zero;
             GetComponent<Rigidbody2D>().AddForce(jumpForce);
             jumpCount--; // Reduce the amount of jumps left by 1
         }
         // If the character is touching the ground
         if (grounded)
         {
             jumpCount = 4; // Reset amount of jumps left to 4
         }
     }
     
     void OnCollisionEnter(Collision col) // When the character collides with something
     {
         if(col.collider.tag == "ground") // If the object has the tag "ground"
         {
             grounded = true;
         }
     }
     void OnCollisionExit(Collision col) // When the character stops colliding with something
     {
         if(col.collider.tag == "ground") // If the object has the tag "ground"
         {
             grounded = false;
         }
     }
 }



Comment
Add comment · Show 8
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image meat5000 ♦ · Oct 14, 2015 at 01:32 PM 0
Share

Add more info. You do not even indicate a problem.

avatar image Joppix meat5000 ♦ · Oct 14, 2015 at 02:01 PM 0
Share

Corrected!

avatar image meat5000 ♦ Joppix · Oct 14, 2015 at 02:14 PM 0
Share

Is grounded properly resetting your jump count (which should probably be an int not a float)?

Use Debug.Log

Show more comments
Show more comments
avatar image Joppix meat5000 ♦ · Oct 14, 2015 at 02:43 PM 0
Share

ok, i did it, but the console does not show anything

avatar image meat5000 ♦ · Oct 14, 2015 at 03:33 PM 0
Share

I think you have unchecked the error fields in the console.

Open it up and make sure the three buttons are marked in the top right.

You should be seeing Debugs and also a warning about not using an f for your float jumpCount = 4;

avatar image Joppix meat5000 ♦ · Oct 14, 2015 at 03:47 PM 0
Share

Cheked, and tey're altredy marked

1 Reply

  • Sort: 
avatar image
0

Answer by Konomira · Oct 14, 2015 at 02:59 PM

if (Input. GetKeyDown("space") && jumpCount > 0) there is a space after "Input." looks like a syntax error, remove the space and try it.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Joppix · Oct 14, 2015 at 03:02 PM 0
Share

@$$anonymous$$onomira nope, that's not the problem, i've just tried

Follow this Question

Answers Answers and Comments

40 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Player loses momentum when landing 0 Answers

Player does not jump? 0 Answers

Can not use properties of rigitbody2d 1 Answer

Player won't stop moving when key is released 1 Answer

Corgi Engine - Character glitches with "jump" animation on top of a ladder 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges