Hi guys, i’d like to move my player with rigidbody2d by swipe left and right, and i’d like to move it into a specific point, i saw the api mathf.clamp to create the movement limitations, but i don’t know how to create multiple limitations
I post a gif to make you understand better:
using UnityEngine;
using System.Collections;
public class Gestures : MonoBehaviour {
public Rigidbody2D playerRigibody2D;
public Transform playerTransform;
public float speed;
public Vector2 movementRight;
public Vector2 movementLeft;
private GameController gamecontroller;
void Start ()
{
GameObject GameControllerObject = GameObject.FindWithTag ("GameController");
if (GameControllerObject != null) {
gamecontroller = GameControllerObject.GetComponent <GameController> ();
}
if (gamecontroller == null) {
Debug.Log ("Cannot find 'GameController' script ");
}
}
void OnEnable(){
EasyTouch.On_SwipeEnd += On_SwipeEnd;
}
void OnDestroy(){
EasyTouch.On_SwipeEnd -= On_SwipeEnd;
}
void On_SwipeEnd (Gesture gesture)
{
switch (gesture.swipe) {
case EasyTouch.SwipeDirection.DownLeft:
case EasyTouch.SwipeDirection.UpLeft:
case EasyTouch.SwipeDirection.Left:
playerRigibody2D.rigidbody2D.velocity = movementLeft * speed;
break;
case EasyTouch.SwipeDirection.DownRight:
case EasyTouch.SwipeDirection.UpRight:
case EasyTouch.SwipeDirection.Right:
playerRigibody2D.rigidbody2D.velocity = movementRight * speed;
break;
}
}
void FixedUpdate ()
{
}
}