Why is my multi touch not working?
if (Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Began)
{
if (!EventSystem.current.IsPointerOverGameObject(Input.touches[0].fingerId))
{
if (!anim.GetCurrentAnimatorStateInfo(0).IsName("PlayerAttack"))
{
anim.Play("PlayerAttack");
}
}
}
I have a joystick in my canvas and used this code so that the player doesn't attack when the joystick is touched but now my game is not letting me move the joystick and attack at the same time.
maybe there are other ui elements your finger is clicking?
if you are trying to read more than 1 touch by frame (ie screen touch and joystick touch at the same time) you need to iterate trough the array of input touches
for (int i = 0 ; i < Input.touchCount ; i++){
//change all Input.touches[0] by Input.touches[i] inside the if
//(is your first if without the Input.touchCount > 0)
if (Input.touches[i].phase == TouchPhase.Began)
{
if (!EventSystem.current.IsPointerOverGameObject(Input.touches[i].fingerId))
{
if (!anim.GetCurrentAnimatorStateInfo(0).IsName("PlayerAttack"))
{
anim.Play("PlayerAttack");
}
}
}
Answer by $$anonymous$$ · Feb 18, 2019 at 05:56 PM
I have a joystick in my canvas and what i' m trying to achieve is that when the player touches the screen anywhere except the joystick he attacks. I did this by using this code but now I can't move the joystick and attack at the same time.
Your answer
Follow this Question
Related Questions
Two finger tap causes jump bug 0 Answers
Android Controls 1 Answer
Error CS1026: Unexpected symbol ;, expecting ) 0 Answers
How to separate a Tap from a Swipe? 0 Answers