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 shepsaus000 · Dec 14, 2015 at 06:52 PM · scripting problem

Touch problems

I would like the following script to move an object as you move your finger across the mobile device. This script gives me no compiler errors, but it also doesn't register... like at all. The debug isn't even popping up in the console.

 using UnityEngine;
 using System.Collections;
 
 public class PlatformSpawning : MonoBehaviour {
     Ray ray;
     RaycastHit hit;
     public GameObject platform;
     public GameObject region;
 
 
     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)){
 
 
             if (hit.transform.name == "region" || hit.transform.name == "Platform") 
                 {
                 platform.transform.position = hit.point;
                         Debug.Log ("Touched");
 
                 }
                 }
             }
         }
     }
 }

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

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by G4merSylver · Dec 15, 2015 at 02:50 AM

I am not exactly sure, but I think the reason there is no response might be because you arent exactly giving it an touch input? For the movementtracking of the mouse you would need to use input.getaxis. Touch input is for touch devices... I think? Also are you using the correct way of getting your touches by input.gettouch?

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
avatar image
0

Answer by phil_me_up · Dec 14, 2015 at 07:57 PM

Are you running this on a PC / Mac? If so then the Input.touchCount will always be 0 as mouse input is handled separately. You'll need to expand your code to check the Input.mousexxx data.

Comment
Add comment · Show 2 · 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 shepsaus000 · Dec 15, 2015 at 06:41 PM 0
Share

Can you elaborate a bit more? I think I understand what you're saying, but I'm not sure.

avatar image Eno-Khaon shepsaus000 · Dec 15, 2015 at 06:46 PM 0
Share

On a computer, there's generally no such thing as a "touch" event. You would need separate handling for such inputs as Input.mousePosition and Input.Get$$anonymous$$ouseButtonDown. Otherwise, while "touch" input is not invalid on a computer, it will most likely not be recognized and called.

avatar image
0

Answer by OncaLupe · Dec 15, 2015 at 02:11 AM

Your raycast is only 100 units, are you sure that's far enough to reach objects in the game? Do the objects have Colliders on them and named exactly as the checks are looking for? I'd add some more Debug.Logs, one for each loop/if block to see where it's stopping.

Also, you create variables 'ray' and 'hit' at the start of the class, then new ones in the Update(). Only one of these sets are needed, though aren't hurting anything.

(Note: I don't have a device to test on, but it looks good to me and no compile errors as you mentioned.)

 using UnityEngine;
 using System.Collections;
 
 public class PlatformSpawning : MonoBehaviour
 {
     public GameObject platform;
     public GameObject region;
 
     void Update () {
 
         if (Input.touchCount >= 1)
         {
             Debug.Log("Touching start");
             foreach (Touch touch in Input.touches)
             {
                 Debug.Log("Checking a touch");
                 Ray ray = Camera.main.ScreenPointToRay(touch.position);
                 RaycastHit hit;
                 if(Physics.Raycast (ray, out hit, 100))
                 {
                     Debug.Log("Raycast hit : " + hit.transform.name);
                     if (hit.transform.name == "region" || hit.transform.name == "Platform") 
                     {
                         platform.transform.position = hit.point;
                         Debug.Log ("Touched");
                     }
                 }else
                     Debug.Log("Nothing hit");
             }
         }
     }
 }
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 shepsaus000 · Dec 15, 2015 at 06:49 PM 0
Share

I can tell you right now that none of the debugs are registering at all. Including the nothing hit one.

avatar image
0

Answer by hexagonius · Dec 15, 2015 at 07:21 PM

If you do not even receive the "Touching start", there's just no input, or the script is attached to nothing. if it is though, use Unity remote on a connected touch device (cable) and be sure to see the game view on it, then try.

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

35 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can one rotate an object instantly? 2 Answers

Card Game like yu-gi-oh 1 Answer

First Person Controller - Problems with footstep audio being played too fast. 0 Answers

Iterate through area descibed by objects 1 Answer

MonoType Behavior 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