Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Dogg · Aug 28, 2014 at 10:55 AM · 2djumpforce

Increase Jump Through Mouse Clicks?

A quick beginner question(I know shameful). How can I increase the jump force of my Player depending on how many mouse clicks i do? For an example If I click the mouse 1 time, it would increase my Jump force by 10. If i click it 3 times it would increase it by 30 since 10 x 3 = 30. If I click it 100 times it would increase it by 1000, and so on. So how can this be done? I know a simple mouse click if statement, but not by how many times the mouse is clicked. That's the hard part. Here's my Player script, very simple:

 public class TestCharacterController : MonoBehaviour {
 
     public float maxSpeed = 10f;
     bool facingRight = true;
 
     public float jumpForce = 1f;
 
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void FixedUpdate () {
     
         float move = Input.GetAxis ("Horizontal");
         rigidbody2D.velocity = new Vector2 (move * maxSpeed, rigidbody2D.velocity.y);
 
         if (move > 0 && !facingRight)
                         Flip ();
                 else if (move < 0 && facingRight)
                         Flip ();
     }
 
     void Update(){
 
         if(Input.GetMouseButton(0))
         rigidbody2D.AddForce(new Vector2(0, jumpForce));
     }
 
     void Flip()
     {
         facingRight = !facingRight;
         Vector3 theScale = transform.localScale;
         theScale.x *= -1;
         transform.localScale = theScale;
     }
 }
 

I NEED it to keep track of how many times the mouse button is click. Then it could add it up and apply it when I want it to(things just got complicated, which is fun!). So to sum it up, clicks mouse button how every many times, keep track of how many mouse clicks and adds the proper jump force, it stores it away until I want to apply it at any time(whether by coroutines or something else). Simple? Maybe but a little too complex for me. Please help if you can.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Noob_Vulcan · Aug 28, 2014 at 11:21 AM

Simply take a variable say

 int clickCount;  // Can be static if you want
 
 if(Input.GetMouseButton(0)){
     clickCount++;
 
     //can put conditions based number of clicks . eg
     if(clickCount==5)
     // Add this much force and after this you want to reset the clicks just set clickCount==0
 
      rigidbody2D.AddForce(new Vector2(0, jumpForce));
 }

I hope this is what you want.

Comment
Add comment · Show 4 · 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 Dogg · Aug 29, 2014 at 03:38 AM 0
Share

I'm starting to get what i want, but i'm having a problem. The number of mouse clicks don't work anymore. So now I only have to press it once in order to jump, which is not what I want. I use a coroutine for reasons that are not too important, but anyways here's the code:

 // Use this for initialization
     void Start () {
         mikki = false;
         StartCoroutine (Clicks());
     
     }
     
     IEnumerator Clicks()
     {
 
         while(true){
         yield return new WaitForSeconds (0.001f);
         if (Input.Get$$anonymous$$ouseButton (0)) {
                         clickCount++;
             
                         if (clickCount == 5){
                                 mikki = true;
                 Debug.Log("WOR$$anonymous$$ YOU BB");
             }
           }        
         }
     }

How can I fix the number of mouse clicks?

avatar image Noob_Vulcan · Aug 29, 2014 at 05:14 AM 0
Share

@Dogg : your input code should be in Update. the way you used may fail in some cases.

clickCount is not increasing when you click ?????

avatar image Noob_Vulcan · Aug 29, 2014 at 05:16 AM 0
Share

what exactly you want ...tell me the whole scenario

avatar image Dogg · Aug 29, 2014 at 11:28 AM 0
Share

Yes, it would appear so. The click count is no longer working now that I moved it out of Update and into the Ienumerator, but that shouldn't matter. I only want the click count to be once and after a short amount of time disable me being able to click the mouse again. Only once on start, and not every frame or whatever Update does again. What I'm trying to do is, click mouse 5 times, increase jump, disable me being able to click the mouse again, and loop the jump so it looks like I'm flying. That's why on the code you see while(true), because that seems to loop the jump and get what I want, but again the mouse clicks aren't working properly.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

23 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

Related Questions

Multiple Cars not working 1 Answer

please i beg of you help!!!!!!!!!!!!!!! 2 Answers

How to make Sphere to jump? 2 Answers

Switching Cameras at runtime 1 Answer

How to move 2D object on touch in Unity 4.3 1 Answer


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