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 /
avatar image
1
Question by Raymond 2 · May 24, 2011 at 09:01 AM · androidtouch

Android touch input

I want a simple touch input on the android, just when i touch the screen(anywhere) that something happens, anyone got any idea on how to do this?

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

3 Replies

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

Answer by Henrique Vilela · May 24, 2011 at 12:16 PM

 void Update() {
     if (Input.touchCount == 1) {
         // Do something
     }
 }
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 GerTaitus · May 30, 2013 at 04:29 PM 1
Share

wouldn't it be better using >=1?

avatar image Dogg · Aug 13, 2014 at 03:41 AM 0
Share

Does this also work for IOS? Yes I know this is a old question but I'm very new to Input since I'm trying to make my game from windows controls to Ipod/Ipad controls. I've been working in windows this whole time. Anyways I tried using that piece of code for this:

 if (grounded && Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.Space)) {
 anim.SetBool ("Ground", false);
                                 rigidbody2D.AddForce (new Vector2 (0, jumpForce));

By just replacing the if statement with the one you posted, but nothing seems to work(the Player is not jumping). I'm testing this on Unity by the way, not some simulator or an actual device.

avatar image Dogg · Aug 19, 2014 at 01:31 AM 0
Share

Anyone know? Please do tell.

avatar image
0

Answer by MDennis · May 24, 2011 at 09:04 AM

http://unity3d.com/support/documentation/Manual/Input.html#AndroidInput

that should get you started

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 Raymond 2 · May 24, 2011 at 09:10 AM 0
Share

Thanks that should help me :)

avatar image Raymond 2 · May 24, 2011 at 11:44 AM 1
Share

i tried this: var Speed = 8 ; var rotateSpeed = 40; var start = false;

var distanceCheck = 0;

var Target : Transform ;

function Update () { distanceCheck = Vector3.Distance(Target.position, transform.position); if(start) { transform.Translate(Vector3.right Speed Time.deltaTime); for (var touch : Touch in Input.touches) { if (touch.phase == TouchPhase.Began) { transform.Rotate(Vector3.forward rotateSpeed Time.deltaTime); } else { transform.Rotate(Vector3.forward -rotateSpeed Time.deltaTime); } } } }

But when i test on the android, there is no movement happening at all, i used the input for space for testing and then everything worked but now not anymore,, anyone has any idea??

ps: i just need that when i press anywhere in the screen

avatar image MDennis · May 24, 2011 at 11:50 AM 0
Share

If you just want to be able to press anywhere on the screen, i will tell you what i did for the iPhone. Which you can easily do for Android.

On the main camera create a child, which will be a plane. Remove the mesh and mesh collider from it and place a plane collider on it. Now position it so what ever the camera is facing it is looking through that plane as if it is a window. $$anonymous$$ake sure it is also trigger on by the way. Now place a script onto the plane so that whenever the player presses the screen it interacts with the plane and something happens.

So for example on my script;

var THEGA$$anonymous$$EOBJECTYOUWANTSO$$anonymous$$ETHINGTOHAPPEN: GameObject;

function FixedUpdate() { if(Input.touchCount >=1) { var touch: Touch = Input.touches[0]; if(touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled) { do what you wanted here } else { stop what you wanted here } } }

hopefully that will help now

avatar image
0

Answer by mivi06 · Jan 15, 2012 at 05:46 PM

i have unity 3.4 with license full! i build it .apk it opend on my phone but doesnt function, becz i neead a script for touch. my script is whenever i click with the mouse the box disappears. how can i change the mouse click to finger touch? this is my script

function OnMouseDown(){

//if cube's texture isn't locked texture then it loads level number which we gave it in editor

if(renderer.material.mainTexture != lock){

Application.LoadLevel(loadlevel);

}

}

Please Help!

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 Raymond 2 · Jan 16, 2012 at 12:42 PM 0
Share

I figured it out eventually, don't know if you found it yourself already, but if the control is when you touch anywhere on the screen something happens, then you'll need this code:

if(Input.TouchCount == 1) { //do something }

if it doesn't work change the capitals of TouchCount to touchCount or Touchcount

avatar image mivi06 · Jan 16, 2012 at 01:10 PM 0
Share

thkx raynond i used dave's method and it workes like a charm! rlly thank u!

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

7 People are following this question.

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

Related Questions

Is touch began guaranteed? 0 Answers

Android Multi-Touch Issue 2 Answers

2D Camera (Android, Iphone) 1 Answer

Create on Gui controls for Mobile Devices (Android) 1 Answer

Best Way to make Swipe to Look function via touch. (Android) 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