blender baby
blender baby

Reputation: 5

Unity Android touch Input reset

first, I'm sorry for my english ahead
I want player to move when they input one touch and to use skill only when input two touches.
Below code seems fine except when I input two touches then took off the 'first touch' and re-input touch, it goes wrong.
but if I took off the strong textsecond touch it works fine.

    public class Test : MonoBehaviour {

        private void Update() {
            if(Input.touchCount > 0) {Movement();}
            if(Input.touchCount > 1) {Skill();}
        }
        private void Movement() {

            Vector2 inputPos = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
            transform.position = Vector3.MoveTowards(transform.position, inputPos, 30f * Time.deltaTime);
        }
        private void Skill() {print("skill fired");}

Working as Intended
//  [1]: https://imgur.com/ngjoabY
//  [2]: https://imgur.com/kkDAGEW



Problem the second reinput should fire skill instead of moving toward that
//  [3]: https://imgur.com/gD0x8rP
//  [4]: https://imgur.com/o06mJgs
    }

after you give it two touches, and took off the first one, second touch becomes the first one and it is caught in if(Input.touchCount > 0) {Movement();}.
So in this stage, if you input again that should be GetTouch(1) right?
but that re-input second touch is become GetTouch(0)!!
So object that is supposed to use skill, moves to the second input position I've done everything I could but I couldn't find a solution.
I was thinking if I could flush the buffer for Input Touches, I can do this but it has just Get methods.
And Input.simulateMouseWithTouches It didn't work.
Touch class variables can't even be compared with null.

Upvotes: 0

Views: 1066

Answers (1)

Mansoor Ahmad Khan
Mansoor Ahmad Khan

Reputation: 134

is it necessary to get touch counts?
you can use crossplatforminput. To import CrossPlatForm Assets->Import->CrossPlatFormInput.

after Importing Go To Standard Assets->CrossPlatformInput->Prefabs->5 Different prefabs ,choose that suits your project better.

Upvotes: 0

Related Questions