Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am trying to drag my game object using iphone touch. I am having the problem that my object is dragging wherever on the screen I touch, I want it to drag only when placing my finger on object. Here is my code:

if (Input.touchCount > 0) {                         
   Touch theTouch = Input.GetTouch (0);                                 
   Ray ray = Camera.main.ScreenPointToRay(theTouch.position);    

     if(Physics.Raycast(targetItem.transform.position, ray.direction,1.5f))             
       {                 
     if(Input.touchCount == 1) {                                                              

             float scrollDeltaX = theTouch.deltaPosition.x;
             float scrollDeltaY = theTouch.deltaPosition.y;

             scrollDistanceX = Mathf.Clamp(scrollDistanceX+scrollDeltaX*Time.deltaTime,-18,15); //limits of my screen              
             scrollDistanceY = Mathf.Clamp(scrollDistanceY+scrollDeltaY*Time.deltaTime,-10,12.5f);                              

             targetItem.transform.position = new Vector3(scrollDistanceX,scrollDistanceY,targetItem.transform.position.z);

          }                    
   }
}  
share|improve this question
ok, I have done with it, just used hit.collider.gameObject.tag == "Player", but object is not dragging v smoothly on simulator, is this is bcz of simulator ? – Syed Oct 6 '11 at 14:35

closed as too localized by Byte56, bummzack, Sean Middleditch, Trevor Powell, Tetrad Mar 12 at 20:06

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

Browse other questions tagged or ask your own question.