- Home /
change an image with touch/drag(enable/disable gameObject or Component)
i would like to enable and disable a component by dragging, i am making a motorcycle game where the player drags up and down to move around the screen, i want to tilt him down when theyre dragging downwards.
it currently works fine like this, except for the deltatouch, how do i do it correctly?
if ( touch.deltaPosition.y < 0 || Input.GetAxis("Vertical") > 0)
{
// Bike is moving up.
playerStraight.gameObject.SetActive(false);
playerDown.gameObject.SetActive(false);
playerUp.gameObject.SetActive(true);
//Debug.Log ("Pressed UP");
}
else if (touch.deltaPosition.y > 0 || Input.GetAxis("Vertical") < 0)
{
playerStraight.gameObject.SetActive(false);
playerDown.gameObject.SetActive(true);
playerUp.gameObject.SetActive(false);
//Debug.Log ("Pressed DOWN");
}
else
{
playerStraight.gameObject.SetActive(true);
playerDown.gameObject.SetActive(false);
playerUp.gameObject.SetActive(false);
}
Comment
Your answer
Follow this Question
Related Questions
Help to fix my drag code [SOLVED] 1 Answer
Simultaneous Touch Drag Controls 0 Answers
setactive true in OnBeginDrag 1 Answer
Detect screen tap vs. drag 2 Answers
Touch Drag GameObject Found 1 Answer