- Home /
Fix Swipe problem
I'm using and if the position of the character is bigger than 80 on the x axis. It's not possible to swipe to the right. And if the position of the character is smaller than -80 on the x axis, It's not possible to swipe to the left. This is the whole script:
var minMovement: float = 20.0f;
var sendLeftMessage: boolean = true;
var sendRightMessage: boolean = true;
var MessageTarget: GameObject = null;
private var StartPos : Vector2;
private var SwipeID = -1;
function Update ()
{
if (MessageTarget == null)
MessageTarget = gameObject;
for (var T in Input.touches)
{
var P = T.position;
if (T.phase == TouchPhase.Began && SwipeID == -1)
{
SwipeID = T.fingerId;
StartPos = P;
}
else if (T.fingerId == SwipeID)
{
var delta = P - StartPos;
if (T.phase == TouchPhase.Moved && delta.magnitude > minMovement)
{
SwipeID = -1;
if (Mathf.Abs(delta.x) > Mathf.Abs(delta.y))
{
if (sendRightMessage && delta.x > 0)
MessageTarget.SendMessage("OnSwipeRight", SendMessageOptions.DontRequireReceiver);
else if (sendLeftMessage && delta.x < 0)
MessageTarget.SendMessage("OnSwipeLeft", SendMessageOptions.DontRequireReceiver);
}
}
else if (T.phase == TouchPhase.Canceled || T.phase == TouchPhase.Ended)
SwipeID = -1;
}
}
}
function OnSwipeLeft()
{
transform.position -= Vector3.right*80;
animation.CrossFade("LeftMove");
if (transform.position.x > 80){
//I don't have any idea what to do to prevent the character goes further than x=-80
//If the x position is -80, you can't slide to the left anymore
}
}
function OnSwipeRight()
{
transform.position += Vector3.right*80;
animation.CrossFade ("RightMove");
if (transform.position.x > 80){
//I don't have any idea what to do to prevent the character goes further than x=80
//If the x position is 80, you can't slide to the right anymore
}
}
But I have to do something with this part of the script:
function OnSwipeLeft()
{
transform.position -= Vector3.right*80;
animation.CrossFade("LeftMove");
if (transform.position.x > 80){
//I don't have any idea what to do to prevent the character goes further than x=-80
//If the x position is -80, you can't slide to the left anymore
}
}
function OnSwipeRight()
{
transform.position += Vector3.right*80;
animation.CrossFade ("RightMove");
if (transform.position.x > 80){
//I don't have any idea what to do to prevent the character goes further than x=80
//If the x position is 80, you can't slide to the right anymore
}
}
Please help someone :D
EDIT
Someone who can help me? I tried something, but it was nothing.
So, the player will always be at -80, 0 or +80? In that case, just change the SwipeLeft if to if(x>-40)
(picked -40 just because it's in-between.) Likewise rightSwipe can check x<40
.
Answer by Fornoreason1000 · May 09, 2013 at 10:09 PM
just make swipe do nothing, you can do this by making you swipe commands conditional or setting the sensitivity to 0
Your answer
Follow this Question
Related Questions
Walls move when the character moves ! 4 Answers
Unity - Avatar problem? 0 Answers
mass placed trees dont collide 1 Answer
error CS0103: The name `FiredShot' does not exist in the current context 2 Answers