Click Drag not working on iphone

Hey again all. I have a click drag script here that runs fine otherwise and doesn't produce errors but once I get the game on my iphone it just doesn't work. Any one have an idea why? Here's the code.


using UnityEngine; using System.Collections;


public class clickDragMesh : MonoBehaviour {

private Vector3 screenPoint; private Vector3 offset;

void OnMouseDown() { screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);

offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));


void OnMouseDrag() { Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);

Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset; transform.position = curPosition;



As always, thank you for the help!

more ▼

asked Apr 17, 2011 at 05:47 AM

Earth-O-Matic gravatar image

70 28 20 31

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

You cannot use mouse controls on your iPhone, but has to use touch events instead. The touch events can be read from the Input class.


This means that you have to code the "mouse drag" functionality yourself.

more ▼

answered Apr 17, 2011 at 08:09 AM

Mortennobel gravatar image

1.9k 25 28 55

I redid the code and now I can click and drag.

Apr 18, 2011 at 02:39 AM Earth-O-Matic
(comments are locked)
10|3000 characters needed characters left

Here is the code if anyone is interested. I'm still having trouble with stopping the drag and doping the object when I lift my finger. This is just the drag code I used. I'm using a modified version of this code currently to touch and drop - no drag. Would like drag though if I can figure it out or someone else can chime in.

#pragma strict

var cam : Camera; var hit : RaycastHit;

function Start() { cam = Camera.main; }

function Update () { if(iPhoneInput.touchCount == 1) { var touchPos : Vector2 = iPhoneInput.touches[0].position; var ray : Ray = cam.ScreenPointToRay(touchPos);


         transform.position = cam.ScreenToWorldPoint(Vector3(touchPos.x,touchPos.y,10));


more ▼

answered Apr 18, 2011 at 02:41 AM

Earth-O-Matic gravatar image

70 28 20 31

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Apr 17, 2011 at 05:47 AM

Seen: 2536 times

Last Updated: Apr 17, 2011 at 05:47 AM