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 Anonymous 1 · Aug 14, 2011 at 01:16 PM · androidiphonetouchsimple

Question about Unity Touch Interface For Android

I need help on unity's touch interface, I want to 'do something' when the user touches the gameobject (a cube), for example : load level 1 when user touches the cube.

Can anyone please help me ? Thank you For your time.

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

Answer by Peter G · Aug 14, 2011 at 03:21 PM

This should be fairly simple. Iterate through all the touches, ray cast for each one, and check if you hit anything:

 function Update () {
     var tapCount = Input.touchCount;
     for (var i = 0; i < tapCount; i++) {
          var touch = Input.GetTouch(i);
          var hit : RaycastHit;
           if (Physics.Raycast ( Camera.main.ScreenPointToRay(touch.position) ,  out hit ) ) {
                   //Do stuff with the `hit` information
           }
      }
 }
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 Anonymous 1 · Aug 14, 2011 at 03:34 PM 0
Share

Errors : " 1 . Assets/$$anonymous$$y Files/Scripts/EAi.js(6,85): BCE0044: expecting ), found 'hit'. on 6th line

2 . Assets/$$anonymous$$y Files/Scripts/EAi.js(6,91): BCE0043: Unexpected token: ). on 6th line

3 . Assets/$$anonymous$$y Files/Scripts/EAi.js(8,12): UCE0001: ';' expected. Insert a semicolon at the end. on 8th line "

How is this even possible ?

avatar image Waz · Aug 14, 2011 at 03:47 PM 0
Share

Remove the out, that's a C# keyword only, not needed in JS.

avatar image Anonymous 1 · Aug 15, 2011 at 03:44 AM 0
Share

alright it did the job but whenever i touch near the cube it executes the 'do something' code in my case ( transform.gameObject.tag = "currentEnemy"; ) . I want that the user touches the cube not its near surroundings . and another thing how can i connect two scripts for example : Function update() { connectedscript.execute }

something like that. Thank you

edit : it also 'do something' when i rotate the camera ,,, :(

avatar image Peter G · Aug 15, 2011 at 02:07 PM 0
Share

I don't have the time to answer all your questions, and many of them have been answered before so you should be able to find them. I will answer the first question though:

You need some conditional to make sure that when you hit the cube it returns true and every other time its false. You can compare the name or the tag or check if it has a given component attached (`GetComponent() != null`)

To access another script, you want to use either GetComponent() or FindObjectsOfType() generally to access another script. Then, when you have an instance of your script ready, you can call functions with it.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Touch Hold for Power 1 Answer

Adroid Input 1 Answer

InputManager vs iPhone/Android 2 Answers

2D Camera (Android, Iphone) 1 Answer

Making 2D On screen buttons for movement 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