OK,
I’ve searched every answer, every thread, read all the documents and I still can’t figure this out.
All I want the script to do is allow the user to drag multiple spheres with individual fingers at the same time to different positions on the screen.
And it seems like it should be so easy.
I wrote this code for dragging objects in iOS with multi-touch.
var obj : GameObject;
private var objposition : Transform = null;
private var selected : boolean = false;
function Awake() {
Input.multiTouchEnabled = true;
if (obj) {
objposition = obj.transform;
}
}
function FixedUpdate () {
if (obj) {
var cam : Camera = Camera.main;
for (var touch : Touch in Input.touches) {
var ray = Camera.main.ScreenPointToRay(touch.position);
var hit : RaycastHit;
if (touch.phase == TouchPhase.Began) {
if (Physics.Raycast(ray, hit, 100)) {
if (hit.collider.gameObject == obj) {
selected = true;
}
}
}
else if (touch.phase == TouchPhase.Moved) {
if (selected == true) {
var cameraTransform = cam.transform.InverseTransformPoint(0, 0, 0);
var touchPosition = cam.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, cameraTransform.z));
objposition.position.x = touchPosition.x;
objposition.position.y = touchPosition.y;
}
}
else if (touch.phase == TouchPhase.Ended) {
if (selected == true) {
selected = false;
}
}
}
}
}
This code should work, but it doesn’t.
The objects move but Multi-touch doesn’t work so you can’t move more than one at a time.
Could someone please point out whats wrong with this or what I should do. I’m completely stumped.
Yes, I’m strait up just asking for help.
And of course thank you.
I also wanted to post this so there will be a Multi-touch drag object script out there for anyone who runs into the same problem and needs it. That’s why I put it on UForum instead of UAnswers.