- Home /
How to make a dragable cube? (iphone)
Hey guys any idea of how to make a cube dragable, I want to touch the screen and be able to move the cube around with my finger.
I know it is something simple but I can not figure out how.
Comment
Answer by Grcan SERBEST · Feb 24, 2011 at 11:44 PM
Hello Noah,
You can get touch position when the condition occurred and you can synchronize cube's position to touch position.
Example ;
function Update() {
var touchpoint : iPhoneTouch = iPhoneInput.GetTouch(0);
if (touchpoint.phase == iPhoneTouchPhase.Began) {
var ray = Camera.main.ScreenPointToRay( Vector3(touchpoint.position.x, touchpoint.position.y));
var ray = Camera.main.ScreenPointToRay(touchpoint.position);
var hit : RaycastHit;
if(Physics.Raycast(ray, hit)) {
cubelocation = hit.point;
}
}
}
}
Regards
Grcan