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 PuzzleBox · Dec 10, 2011 at 01:00 AM · inputiphonetouchipad

Working with Touch screens...

I got these instantiated objects which are clones. Currently I have them setup to react when clicked using 'OnMouseDown()' function. How can I get the same effect but on a iPad and iPhone.

 function OnMouseDown () {
     animation.Play("TruckerprivateRun");
     ScoreController.Points += tap + 100;
     audio.Play();
 }

Continued...

I found a Raycast script that could work. I made it to where when ever an object that has a the Tag "Target" is touched it activates the function "OnMouseDown." Is this possible or are their changes I should make?

 function Update () {
 
   var touch = Input.GetTouch[0];
   if (touch.phase == TouchPhase.Began) {
       var ray = Camera.main.ScreenPointToRay (touch.position);
       var hit: RaycastHit;
       if (Physics.Raycast (ray, hit)) {
         if (other.gameObject.CompareTag ("Target")) {
             gameObject.SendMessage ("OnMouseDown");
         }
       }
     }
   }
 }
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 PuzzleBox · Dec 13, 2011 at 02:10 AM 0
Share

I found this script, will it work?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by dannyskim · Dec 10, 2011 at 11:31 PM

You can use the Input.touches:

http://unity3d.com/support/documentation/ScriptReference/Input-touches.html

or, you can use Input.GetMouseButton(int), Input.GetMouseButtonDown(int), etc:

http://unity3d.com/support/documentation/ScriptReference/Input.GetMouseButton.html

Of course with the second option, this only detects one finger as far as I'm aware. There may be a way to use Input.GetMouseButton to detect more than one touch, but I'm not aware of how to do that myself.

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 PuzzleBox · Dec 11, 2011 at 01:09 PM 0
Share

So, if by putting one of these on a gameObject it will only trigger if I hit that gameObject? Will it trigger if I touch anywhere?

I tried using Raycast to send$$anonymous$$essage("On$$anonymous$$ouseDown") and that didn't work at all. Please explain, I've been only using On$$anonymous$$ouseDown and OnTriggerEnter type of interaction. :/

avatar image dannyskim · Dec 11, 2011 at 08:09 PM 0
Share

No, Input.Get$$anonymous$$ouseButton detects a mouse down anywhere on the screen. It's up to you to define what gets detected through further RayCast logic.

Take a look at the documentation for Physics.Raycast:

http://unity3d.com/support/documentation/ScriptReference/Physics.Raycast.html

There's an example further down the page on that link that shows you how to use a raycast with mouseposition.

avatar image PuzzleBox · Dec 13, 2011 at 03:16 AM 0
Share

hows this script I added to my question? would that work?

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

iPhone touch events slowdown fps?!? 2 Answers

How do I invert the Y axis in Penelope tutorial? 3 Answers

GameObject following touch input, gesture and speed? 1 Answer

Iphone touch not working 0 Answers

Delay before first touch position changes on iPhone 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