Hi Unikron,
I am making a 2D game in Unity, I have a sprite and two buttons left and right to the sprite in respective direction.
My logic goes this way, on ButtonDown event I move sprite and on ButtonUp I stop moving. I am able to move the sprite in both directions on buttondown event, but when I release one button and suddenly press second button the movement of sprite stops and I have to again press that button to start moving.
Here is my code,
void Start(){
GameObject.Find ("Btn_Left").GetComponent<tk2dButton> ().ButtonDownEvent += MoveLeft;
GameObject.Find ("Btn_Left").GetComponent<tk2dButton> ().ButtonUpEvent += StopMoving;
GameObject.Find ("Btn_Right").GetComponent<tk2dButton> ().ButtonDownEvent += MoveRight;
GameObject.Find ("Btn_Right").GetComponent<tk2dButton> ().ButtonUpEvent += StopMoving;
}
void Update(){
Sprite.transform.Translate(IPDir *0.1f,0,0);
}
void MoveLeft (tk2dButton source)
{
Debug.Log("Left is Pressed");
IPDir = -1;
}
void MoveRight (tk2dButton source)
{
IPDir = 1;
}
void StopMoving (tk2dButton source)
{
IPDir = 0;
}
Everything works great except for that part when I am moving in right and suddenly I release right and press left and viceversa, the sprite stops moving. I had enabled multitouch option in editor, multitouch works great, but when dont know why it is not taking the next ButtonDown event when I am Releasing one button.
Help me regarding this, I searched on forums but could not get closer to my solution.
Regards,
Amit