- Home /
Question by
huglojsk · Feb 02, 2014 at 12:56 PM ·
collisionmovementtagsmultitouch
Multitouch and collision for android
Hi!
I am making my first android game for android and I'm new to unity. I know the basics however.
I am trying to make 2 - 4 different blocks move on the y-axis by touch and dragging. They have to move independently by multitouch. I've got the code for moving them done, however I need to limit them so that the blocks can't go out of the cameras view. Multitouch isn't working either.
(to seperate which object is being touced I use tags "LeftBlock" and "RightBlock")
Here's the code for the blocks:
var speed : float = 0.01;
function Update () {
if (Input.touchCount > 0 &&
Input.GetTouch(0).phase == TouchPhase.Moved) {
{
var ray = Camera.main.ScreenPointToRay (Input.GetTouch(0).position);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit) && hit.transform.gameObject.tag == "LeftBlock")
{
// Get movement of the finger since last frame
var touchDeltaPosition:Vector2 = Input.GetTouch(0).deltaPosition;
// Move object across XY plane
transform.Translate (0,
touchDeltaPosition.y * speed, 0);
}
}
}
}
I would be very grateful for a quick reply.
Thanks,
Adam
Comment