Unity Android touch Input reset











up vote
0
down vote

favorite












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.










share|improve this question


























    up vote
    0
    down vote

    favorite












    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.










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      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.










      share|improve this question













      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.







      c# android unity3d






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 18 at 8:00









      beginner

      55




      55
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          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.






          share|improve this answer





















          • Thank you I didn't even know crossplatforminput exists.
            – beginner
            Nov 19 at 8:43











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53358940%2funity-android-touch-input-reset%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote



          accepted










          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.






          share|improve this answer





















          • Thank you I didn't even know crossplatforminput exists.
            – beginner
            Nov 19 at 8:43















          up vote
          0
          down vote



          accepted










          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.






          share|improve this answer





















          • Thank you I didn't even know crossplatforminput exists.
            – beginner
            Nov 19 at 8:43













          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          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.






          share|improve this answer












          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 18 at 10:32









          Mansoor Ahmad

          748




          748












          • Thank you I didn't even know crossplatforminput exists.
            – beginner
            Nov 19 at 8:43


















          • Thank you I didn't even know crossplatforminput exists.
            – beginner
            Nov 19 at 8:43
















          Thank you I didn't even know crossplatforminput exists.
          – beginner
          Nov 19 at 8:43




          Thank you I didn't even know crossplatforminput exists.
          – beginner
          Nov 19 at 8:43


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53358940%2funity-android-touch-input-reset%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Ottavio Pratesi

          Tricia Helfer

          15 giugno