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.
c#
add a comment |
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.
c#
add a comment |
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.
c#
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#
c#
asked Nov 18 at 8:00
beginner
55
55
add a comment |
add a comment |
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.
Thank you I didn't even know crossplatforminput exists.
– beginner
Nov 19 at 8:43
add a comment |
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.
Thank you I didn't even know crossplatforminput exists.
– beginner
Nov 19 at 8:43
add a comment |
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.
Thank you I didn't even know crossplatforminput exists.
– beginner
Nov 19 at 8:43
add a comment |
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.
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.
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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