using UnityEngine;
using System.Collections;
public class MoveButton : TouchLogicV2
{
[Range(-1,1)]
public int moveDir = 1;//1=right;-1=left
PlayerMovement player;
void Start()
{
player = FindObjectOfType<PlayerMovement>();//This will find our player script, as long as there is only 1 GameObject with "PlayerMovement" on it
}
public override void OnTouchBegan()
{
//watch this touch for when it ends anywhere so we can slow down the player
touch2Watch = currTouch;
}
public override void OnTouchMoved()
{
player.Move (moveDir);
}
public override void OnTouchStayed()
{
player.Move (moveDir);
}
public override void OnTouchEndedAnywhere()
{
//run this check so other touches ending don't cause player to slow down
if(currTouch == touch2Watch)
player.Move(0);//do avoid annoying drift after letting go of button
}
}