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 Dr_GeoFry · Apr 08, 2012 at 10:48 PM · androidjumping

Make a character jump when user taps the screen of an android device

Hi, I have been trying all sorts of code to make my character jump by tapping the screen. This is for an android device. I have no problems making everything work correctly in Xcode, I just an illogical inability to get things working for android devices.

Thanks in advance

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 Graphicated · Apr 09, 2012 at 01:28 AM 0
Share

where are you facing troubles ,with recognizing the touches ? or adding the code to manage the physical action of the gameObject (adding some force in Y axis if it is pointing up) ?

1 Reply

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

Answer by Graphicated · Apr 09, 2012 at 04:37 PM

this will manage each touch (up to five fingers depending on the device). first off all there are 5 situations a Touchphase will face see here : 125Link125

so you have to decide when the action should happen , when beginning touch, or .....

here is a small example that will run whatever you want when the touch begins and if the touch not over five fingers or the user stopped touching:

    void Update()
     {
         int fingerCount = 0;
         foreach (Touch touch in Input.touches) {
           if (touch.phase == TouchPhase.Began && touch.phase != TouchPhase.Canceled)
          {            
              fingerCount++;
              }
         }           
     }
    if (fingerCount > 0)
       {        
         // manage the Vector or Force Manipulation here of the Player Prefab    
       }


Another Example where you manage if it is only 1 finger touching or 2 and so on:

  using UnityEngine;
  using System.Collections;
     
     public class example : MonoBehaviour {
         void Update() {
             int fingerCount = 0;
             foreach (Touch touch in Input.touches) {
                 if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
                     fingerCount++;
                 
             }
     
             if (fingerCount == 1)
                 {
                 print("User has " + fingerCount + " finger(s) touching the screen");
             }else if (fingerCount ==2)
           {
              // do another thing if 2 fingers
           }
         }
     }



hope this will help you to start solving your problem.

Comment
Add comment · Show 3 · 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 Dr_GeoFry · Apr 11, 2012 at 01:15 AM 0
Share

I have it working now, but am a little confused. Why does if (fingerCount > 0) dir.y = -Input.acceleration.x*.5; transform.position.y += dir.y; }

work, but

if (fingerCount > 0) rigidbody.AddRelativeForce (Vector3.up * jumpStrength); }

does not work?

Part of the code is not shown here.

avatar image Graphicated · Apr 12, 2012 at 03:22 PM 0
Share

are you getting any error ? i didnt try this method before

i think it is better to start a new question, so everyone can find it ,, it is a diffrent matter now ^^

avatar image Dr_GeoFry · Apr 13, 2012 at 04:16 AM 0
Share

I think you're right.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Jumping irregularities 1 Answer

How To Create Android 3d Game Jump Button 2 Answers

Constrain Total Number of Jumps 1 Answer

Jump Script for 2D (JavaScript) 0 Answers

Jumping with touch input. 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