- Home /
how to use deltatouch properly?
ive looked around and cant seem to find it, my sincerest apologies if this has been already answered.
im trying to convert some old code i had in monogame to change the players sprite based on drag direction, wanted my player to lean upwards or downwards depending on the delta of the Y axis.
my old code was like this -
void HandleFreeDrag ( object o, GestureEventArgs e )
{
if ( e.Gesture.Delta.Y < 0 )
{
// Bike is moving up.
player.texture = playerUpTexture;
}
else if ( e.Gesture.Delta.Y > 0 )
{
// Bike is moving down.
player.texture = playerDownTexture;
}
else
{
// Bike is either still or moving perfectly horizontal.
player.texture = playerStraightTexture;
}
}
i have tried doing it very similarly in monodevelop for unity and my current code looks like this.
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);
}
(i set gameObjects to be activated and deactivated so i could use different colliders, it works fine in the scene build, just the touch doesnt seem to trigger?)
any help would be greatly appreciated
Your answer

Follow this Question
Related Questions
Dragging UI Image by touch 3 Answers
How Can I Drag the Object With Touch ? (Mobile) 4 Answers
Movement help 0 Answers
Drag and slide camera 0 Answers