So In my project I have some script that codes kinda like this:
for (var i = 0; i++; i < Touchcount) {
if (touched.phase = touchphase.began) {
make a raycast from the screenpointtoray
if (hit raycastwall) {
does the stuff here
}
}
}
(sorry for my bad pseudo code)
Ok so with this code it works I would say 90% of the time. The other 10% what happens is when someone touches and holds or touches and moves their finger on the screen, upon the next touch it doesn’t recognize anything. I don’t know if this is a glitch or if someone knows if maybe i can check the phases and if it is moved or ended I can use a return to just reset the update function or end it for that matter?
It just boggles me because I have no code that turns off the raycast wall collider I am using, and nothing else effects the producing of a raycast. Any help here would be great!!
Hard to make suggestions based on your pseudo code. A common mistake is that people don’t look at the Touch.fingerId, and just assume that touch 2 in this frame was the same touch as in the previous frame. In your case, just add some Debug.Log statements to debug what’s not happening - could be the ray cast failing, or your ray cast code not being called.
here is the start of my actual code:
for (var i = 0; i < Input.touchCount; ++i) {
if (Input.GetTouch(i).phase == TouchPhase.Began) {
// Construct a ray from the current touch coordinates from all the fingers
// touching the screen
var mobileRay = Camera.main.ScreenPointToRay (Input.GetTouch(i).position);
var mobileHit:RaycastHit;
if (Physics.Raycast (mobileRay, mobileHit)) {
if (mobileHit.collider.tag == "my tags") {
do stuff here
}
}
What I am doing is looping through all the touches and created raycast from them down. So I’m not specifically looking at touch Ids, just a basic unity example. Wondering if maybe after something happens that I want to I can add in a return to stop the update function because it did what I wanted and I don’t have to check the rest of the touches?
Like I said before whenever I touch and hold a finger down, its like the next touch doesn’t register. Its a fast paced game so I can have the player having to touch twice quickly.
thanks!!
Write a small test app that only has an OnGUI() with a label that displays Input.touchCount. Run that on your device, and do a mix of touches and holds, etc. Do you get the expected number of touches?