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 FrankHHansen · Jan 21, 2014 at 07:08 PM · c#androidinputtouch

Player doesn't stop jumping when stop touching the screen[Android]

Hi. I have some code that checks if the player is touching the screen, then if he's touching withing an area, set -Jump to true and if not, set it to false.

This is the code:

 if(Input.touchCount > 0)
 {
     foreach (Touch touch in Input.touches) 
     {
     Vector3 inputGuiPosition = touch.position;
     inputGuiPosition.y = Screen.height - inputGuiPosition.y;
 
     if(inputGuiPosition.x > Screen.width / 5)
     {
         _jump = true;
     }
     else if(_jump == true)
     {
         _jump = false;
     }
     }
 }

When I touch the screen in the right side, and let go, the player keeps jumping. When I souch the screen in the left side, while the player is jumping, he stops jumping I'm guessing the problem is something the _jump is only set to false, if the player touches somewhere else on the screen.

If that is the case, how do I fix it?

Thanks for reading

-Frank

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
Best Answer

Answer by FrimaMickD · Jan 21, 2014 at 08:13 PM

 if(Input.touchCount > 0)
 {
     foreach (Touch touch in Input.touches)
     {
         Vector3 inputGuiPosition = touch.position;
         inputGuiPosition.y = Screen.height - inputGuiPosition.y;
      
         if(inputGuiPosition.x > Screen.width / 5)
         {
             _jump = true;
         }
         else if(_jump == true)
         {
             _jump = false;
         }
     }
 }
 else
 {
     _jump = false;
 }

Also, this is a very basic programming question, you should review logic and maybe read some more on programmation before sending tech questions.

You basically answered your own question in text, just not in code!

" I'm guessing the problem is something the _jump is only set to false, if the player touches somewhere else on the screen."

The if(Input.touchCount > 0) will do that...

Good luck with your learning :)

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 FrankHHansen · Jan 21, 2014 at 09:50 PM 0
Share

Oh... I moved the

 else
 {
     _jump = false;
 } 

into the foreach because the player would keep jumping if if kept holding down the finger on another button simultaneously.
I should have copied it ins$$anonymous$$d -_- silly me.

Thanks for the help ;)

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

19 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

Related Questions

Input.GetTouch(0).position.x and TouchPhase.Began 1 Answer

Detect Gyroscope's rotation around a single axis? Like a car game. 0 Answers

Mouse and Oculus Touch Controller Inputs 0 Answers

,How Do get Touch input to work with the Player Input Component 1 Answer

Touch Not Working 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