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 Sycohazza · Jun 05, 2012 at 06:02 PM · androidtouchclick

Android clicking to touch

Hi, I am trying to convert my game from windows standalone to an android build.

My issue is for clicking an object i use OnMouseUp function but on android this function doesn't work.

is there any function for android that works the same but for touching? i have searched the Script reference but couldn't find any functions for it.

Thanks in advance, Sycohazza.

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

2 Replies

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

Answer by whydoidoit · Jun 05, 2012 at 06:05 PM

There is this code that makes OnMouseDown work for multiple fingers on real objects with colliders, you could use this or modify it for OnMouseUp...

 //  OnTouchDown.cs
 //  Allows "OnMouseDown()" events to work on the iPhone.
 //  Attach to the main camera.
 
 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class OnTouchDown : MonoBehaviour
 {
     void Update () {
         // Code for OnMouseDown in the iPhone. Unquote to test.
         RaycastHit hit = new RaycastHit();
         for (int i = 0; i < Input.touchCount; ++i) {
             if (Input.GetTouch(i).phase.Equals(TouchPhase.Began)) {
             // Construct a ray from the current touch coordinates
             Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
             if (Physics.Raycast(ray, out hit)) {
                 hit.transform.gameObject.SendMessage("OnMouseDown");
               }
            }
        }
     }
 }
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 Sycohazza · Jun 05, 2012 at 06:07 PM 0
Share

Oh wow i was just using raycast like this about a week ago. Cant believe i didnt think of this, thanks :)

avatar image hackathon99 · Dec 17, 2012 at 08:52 AM 0
Share

what is the equivalent of this for javascript..?

avatar image whydoidoit · Dec 17, 2012 at 09:15 AM 0
Share

Just stick it in a plugins folder and you can use it from either language

avatar image nbtruc · Oct 11, 2015 at 04:24 PM 0
Share

hello ! can we have this code for android please ? It's doesn't work for me :'(

avatar image
0

Answer by ehermite · Nov 28, 2012 at 11:27 AM

isn't suit for android mobile?

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

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

Place for touch and click command. 1 Answer

Right Mouse Click in Android 2 Answers

How to touch, move and rotate 3D objects in XZ? 1 Answer

TouchPhase not firing correctly - Android 3 Answers

Moving an Object to the position of touch 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