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
0
Question by Sobriquet · Jun 20, 2011 at 11:58 PM · gameobjecttouchtouchscreen

Game Object as Touch Trigger

Hello!

I am working on a game for tablets and am trying to make good use out of the touch screen. Right now the goal is to touch the model and make it sneeze. I have succeeded in getting the scripts for this to work but it works if you touch anywhere on the screen. This wouldn't be such a problem except I have a GUI menu that needs to be touchable as well, and right now my scripts for the animation&audio have overridden the GUI. Is there a way to make the character model a touch trigger, so that the rest of the screen doesn't react with a touch?

Here's my current code:

 {
     if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
         animation.Play("sneeze"); 
 }

I have played around with adding Touch.position (doesn't recognize it); I have played with adding var Char : GameObject and different variations of Char.TouchPhase.Began, Char = TouchPhase.Began, etc. I have looked at the forums but I haven't seen this problem presented quite this way.. I would appreciate some help!

Comment
Add comment · Show 2
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 Chris D · Jun 21, 2011 at 12:14 AM 0
Share

In the future, please format any code you post (the 10010101 button) - it makes it easier to read.

avatar image Sobriquet · Jun 21, 2011 at 03:23 PM 0
Share

Thank you for the feedback.

1 Reply

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

Answer by crevelop · Jun 21, 2011 at 12:24 AM

The best you can do is to use layers, raycast your touches and then limit the area and targets by creating a layermask, and ignore the objects or areas that you don't want. In your case, move the desire target object to a custom layer and only raycast to that layer.After that you will be able to accurately process your touch events.

Found this video quite useful:

http://www.youtube.com/watch?v=oOfPMKdJdKk

source code is here:

http://www.revelopment.co.uk/tutorials/unitytutorials/73-howtorotateanobjectbytouch

Hope it helps.

Comment
Add comment · Show 1 · 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 Sobriquet · Jun 21, 2011 at 05:13 PM 0
Share

Thank you, that was very helpful!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

how to detect exact touch location of an object and add new object at the same touch position 2 Answers

Multitouch drag object 0 Answers

Unity iPhone: AddForce to Object after Touch 0 Answers

Rhythm Game - Not all notes on touch are changing sprite. (easy to read) 2 Answers

How would you override Editor object dragging? 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