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 /
This question was closed Aug 02, 2012 at 08:22 AM by shaystibelman for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by shaystibelman · Jun 04, 2012 at 09:20 AM · raycasttouch

Touch interface not working

I was trying to convert my application to mobile, and have encountered a serious problem with the touch interface (Using Raycast). While working very well with a normal scene (picking objects ecc), when implementing the exact same code into a scene that imports asset bundles, it stops working. Touch works on GUI items, but not on the 3D objects I need it to work on. Here's my code:

 #pragma strict
 var Target : GameObject;
 var TargetGrabFunction : GrabNRotate;
 private var cam : Camera;
 
 function Start(){
     cam = Camera.main;
 }    
 function FixedUpdate(){
     if (Input.touchCount > 0) 
     {
         var theTouch : Touch = Input.GetTouch (0);    
         var ray = cam.ScreenPointToRay(theTouch.position);
         var hit : RaycastHit;
         if(Physics.Raycast(ray,hit,100))
         {    
             if(Input.touchCount == 1)
             {    
                 if (theTouch.phase == TouchPhase.Began) 
                  {
                      Target = gameObject.Find(hit.collider.gameObject.name);
                      TargetGrabFunction = Target.GetComponent(GrabNRotate);
                     //using 0, 1 and 2 for my boolean cos I need 3 states of true and false
                      if((TargetGrabFunction.bringOver==0 || TargetGrabFunction.bringOver==2))
                          TargetGrabFunction.bringOver = 1;
                      else 
                          TargetGrabFunction.bringOver = 2;            
                  }
              }
         }
     }
 }

Basically, this code is supposed to enable another external code on the gameobject when it is touched. It works fine on an empty scene with only the gameobject.

Comment
Add comment · Show 10
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 hathol · Jun 04, 2012 at 09:41 AM 2
Share

Why are you using gameObject.Find()? You already have a reference to the GameObject (hit.collider.gameObject) that you can simply assign... This might be the cause of you problem as well btw. (multiple gameobjects with the same name)

avatar image shaystibelman · Jun 04, 2012 at 10:40 AM 0
Share

tried to change it, didn't work. maybe I wrote it wrong? Target = hit.collider.gameObject;

avatar image hathol · Jun 04, 2012 at 11:33 AM 0
Share

Nah, that looks fine to me. What exactly does not work? You should at least get a valid gameObject in any case since a collider can't exist without one and your raycast did hit something.

avatar image shaystibelman · Jun 04, 2012 at 11:42 AM 0
Share

As I said, when in an empty test scene with only 1 object, the object gets hit and the script works. When I use the same scripts on the same object (a simple cube, for the test) in a scene full with other objects and scripts and stuff, and assetbundles downloading in the background, it doesn't work. Thing is that I'm doing it on my galaxy tab 10.1, and my computer is a $$anonymous$$ac, so I can't connect a cable to use the profiler to debug.

avatar image hathol · Jun 04, 2012 at 12:12 PM 0
Share

Well, you could try and replace the touch specific code with normal mouseInput (Input.Get$$anonymous$$ouseButtonDown(0) and Input.mousePosition) so you can debug it in the unity editor to make sure that the function itself is working correctly in your scene (or find out what the problem is if it's not). You can use compiler directives for platform dependent compilation to have both in your code at the same time ( http://unity3d.com/support/documentation/$$anonymous$$anual/Platform%20Dependent%20Compilation.html ).

Show more comments

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by yusufulutas · Jun 05, 2012 at 07:21 AM

first you use different layers. for examle: "default" for first camera , "minimap" for second camera and you do "culling mask = default" for first camera and "culling mask = minimap" for second camera. if you dont use skybox, you can "clear flag = depth only" and you must ray send for every camera

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 shaystibelman · Jun 05, 2012 at 07:26 AM 0
Share

cool, i didn't think of layers. i'll try that, shukran!

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Raycast on touch 3 Answers

How to touch select 3D objects 2 Answers

Make object block a raycast 1 Answer

Continuous detection of object using ray cast 2 Answers

select and drag an object with touch 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