- Home /
 
 
               Question by 
               thomas_1 · Apr 12, 2016 at 04:41 PM · 
                androidtouch controlstouch screen  
              
 
              Touch screen move - android
I have code, and in unity editor is done, but emulator doesn't work, if click anywhere on the screen game off. I have not idea how fix it. Thank you in advance.
 private var ray : Ray;
 private var rayCastHit : RaycastHit;
 function Update () 
 {
     if(Input.GetMouseButton(0)) 
     {
         ray = Camera.main.ScreenPointToRay(Input.mousePosition);
 
         if(Physics.Raycast(ray, rayCastHit))
         {
             transform.position.x = rayCastHit.point.x;
         }
     }    
 }
 
              
               Comment
              
 
               
              Answer by aditya · Apr 13, 2016 at 05:11 AM
Because this code is only for mouse controls and not for touch ...
Problem is fixing, this code work for touch and mouse, I tested on the tablet and mobile phone ;)
Your answer
 
             Follow this Question
Related Questions
TouchInputModule "is no longer required"... 1 Answer
Using Input.touchCount as a button 0 Answers
Touch Control for 2D Game 0 Answers
Grabbing objects for touch controls? how 2 Answers
Touch flip/slide misses 0 Answers