1
\$\begingroup\$

I am stuck with an issue of moving the slider on android mobiles with finger touch event while developing pong game in unity 3D, though its working fine for pc.

This game is developed in 2D environment... please help me if anyone have available solution to this issue enter image description here

Actually I have developed this game for pc so I have code for the movement of slider accordingly as below:

var keyup:KeyCode;
var keydown:KeyCode;
var speed:float=1;

function Update () {
    if(Input.GetKey(keyup))
        rigidbody2D.velocity.y=speed;
    else if(Input.GetKey(keydown))
        rigidbody2D.velocity.y=speed*-1;
    else
        rigidbody2D.velocity.y=0;
}

But now i want to use this game for android mobiles.

\$\endgroup\$
1
\$\begingroup\$

You can create a script attached to the object you want to drag and adapt your code to work inside OnMouseDown() & OnMouseDrag()

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Do OnMouseDown() & OnMouseDrag() will work for android mobile devices ?? \$\endgroup\$ – Santosh Yadav Jul 10 '15 at 7:11
  • \$\begingroup\$ Yes they will work fine. Input.GetKeyDown(KeyCode.Mouse0) will also work for a single tap/touch event \$\endgroup\$ – Justin Markwell Jul 10 '15 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.