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 jin416 · Feb 04, 2014 at 05:14 AM · errortouchscreenscreenshot

the problem of touch screen logic

en hey.....I got a problem of how to create a button on mobile device, firstly I did a little research about touch screen logic, therefore I got this code:

Rect leftIconRect = new Rect (10, Screen.height-110, 150, 100);

Rect rightIconRect = new Rect(170, Screen.height-110, 150, 100);

Rect JumpIconRect = new Rect (Screen.width-160, Screen.height-110, 150, 100);

void Update () {

     foreach(Touch t in Input.touches)
     {
         Vector2 vec = t.position;
         vec.y = Screen.height - vec.y; 
         if(leftIconRect.Contains(vec)) axisH = -1;
         if(rightIconRect.Contains(vec))axisH = 1; 
         if(JumpIconRect.Contains(vec))jumpB = true; 
     }

}

It works!!! but when I build a game for android phone, the "jump"touch was not working as I expected. The "touch" is not like button, so if my finger keep pressing on the screen the jump function will always be true!!

so I wonder is there any way to make the "jump" touch as a general button, just working once when I click it!!!!! I'm not sure did I explain the problem clearly..... thank you....

Comment
Add comment · Show 1
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 Ashish Dwivedi · Feb 04, 2014 at 05:30 AM 0
Share

Can you post your whole script?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by GameVortex · Feb 04, 2014 at 07:31 AM

Touches in Unity have **touchphases** describing what the touch has just done. All you need to do is check if the touch is in the touchphase.began (this is the equivalent of checking if the mouse has just been pressed down), then set the jump variable to true, if it is not set it to false.

Example:

 if(touch.phase == TouchPhase.began)
 {
    jumpB = true;
 }
 else
 {
    jumpB = false;
 }

Read the script reference to learn more about how touchphases work.

Comment
Add comment · Show 2 · 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 jin416 · Feb 04, 2014 at 11:32 AM 0
Share

thanks for your help

avatar image GameVortex · Feb 04, 2014 at 11:36 AM 0
Share

No problem. =) Remember to mark the question as answered if it solved your issue.

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

20 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

Related Questions

System.IO.File error, take a screenShot 2 Answers

Capture Screenshot not working in WebGL 1 Answer

Capturing screenshot with transparent background in 4.3, 2d project 1 Answer

SreenShot, Color become a mess 1 Answer

Animation Scripting C# Error 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