drag game controller around screen

i’m trying to write a script that will allow me to touch an object on the screen of an iPhone and drag it around and when i release it the object stays where i left it, similar to the fruit ninja game (if anyone has played that).

i understand the controls for transforming position of an object using the keyboard but am at a loss as to how i can touch an object and keep the object centre as the touch position.

any ideas / suggestions?

i’ve been experimenting with this method (for mouse first) that i learned on answers earlier

function Update () {
	var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
  	var hit : RaycastHit;
  	if (Physics.Raycast (ray, hit, 1000) && hit.collider.gameObject.CompareTag("GameController")) {
    	self.position = hit.position;
  }
}

For touchscreen stuff, you’ll be wanting to use Touch events. Essentially, you can replace all your references to mousePosition with the appropriate touch events.

It contains the same mouseDown/mouseUp kind of events as you’re used to, but they’re contained in TouchPhase.

I’d advice checking out the DragRigidbody script that’s included in Unity (if you don’t have it in your assets folder, import it). It works perfectly and could serve as a good example for you.