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
EDIT
Someone who can help me? I tried something, but it was nothing.