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 iburnedwater · Apr 21, 2015 at 12:10 PM · inputtouch

Problem getting touch input

 void FixedUpdate () 
     {
         if (Input.touchCount == 1)
         {
             Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
             RaycastHit hit;
             
             if (Physics.Raycast(ray, out hit, 100))
             {
                 Collider[] colliders = Physics.OverlapSphere(hit.point, radius);
 
                 foreach(Collider c in colliders)
                 {
                     if (c.GetComponent<Rigidbody>() == null)
                         continue;
 
                     c.attachedRigidbody.AddExplosionForce(force, hit.point, radius, 
                                                            rise, ForceMode.Impulse);


Hey everyone. I'm trying to create a small mobile game where the user touches the screen and creates explosions to destroy buildings and such. However, I can't seem to get the code for the input right. I've tried to find the information I need in the Unity Documentation, but came up short. If anyone can show me my error or point to a place that can, I'd greatly appreciate it. Thanks for your time!

Comment
Add comment · Show 4
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 iburnedwater · Apr 22, 2015 at 05:43 AM 0
Share

Just an update. Honestly this is the first time I've tried to do anything with mobile scripting so I'm not even sure I'm in the ballpark. But I changed a few things around just trying to make it work and this is where I am now. Am I at least closer?

void Update () { if (Input.touchCount >= 1) { foreach(Touch touch in Input.touches) { Ray ray = Camera.main.ScreenPointToRay(touch.position); RaycastHit hit;

             if (Physics.Raycast(ray, out hit, 100))
             {
                 Collider[] colliders = Physics.OverlapSphere(hit.point, radius);
             
                 foreach(Collider c in colliders)
                 {
                     if (c.GetComponent<Rigidbody>() == null)
                         continue;

                     c.attachedRigidbody.AddExplosionForce(force, hit.point, radius, 
                                                            rise, Force$$anonymous$$ode.Impulse);
avatar image GregoryNeal · Apr 22, 2015 at 06:35 AM 0
Share

I don't have a quote for this, but I believe Input.Get$$anonymous$$ouseButtonDown(0) returns true for taps on a screen for mobile.

avatar image Thorny2000 · Apr 22, 2015 at 07:12 AM 0
Share

Increase the distance you are drawing your ray, change that 100 to 10000 just to make sure it is going far enough. Secondly, I assume you have an object or plane on the screen, you need something for the ray to hit - also make sure the object has a box or mesh collider.

avatar image iburnedwater · Apr 22, 2015 at 05:42 PM 0
Share

I'd like to thank both of you guys for your help. I tried Get$$anonymous$$ouseButtonDown(0) and that seems to have done it. Just to be sure, I went ahead and deployed the test level to my device and sure enough, it accepted the tap input. Again, thanks guys!

0 Replies

· Add your reply
  • Sort: 

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

How do I get a GUI Texture Button to act as a Input Key such as a T button on a key bored or so? 1 Answer

Input.getTouch() vs checking if button is clicked 1 Answer

Touching Falling Objects 1 Answer

two input touch android 1 Answer

Mouse and Oculus Touch Controller Inputs 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