- Home /
Rect.Contains doesn't appear to be working with Input.GetTouch.position
Can anyone figure out why the below code won't work? Its a simplified version of what I'm trying to achieve, but I can't get it going:
function Update () {
var rect = Rect(0,0,Screen.width,Screen.height);
if(rect.Contains(Input.GetTouch(0).position)) {
linkToToggleFireL.onFire();
}
}
Essentially, what I'm telling it is this: if I touch the screen, shoot fire. But if I touch the screen, nothing happens. Ever. The onFire function is contained in another script and the same linkToToggleFireL.onFire(); works elsewhere in this script, just not with the rectangle. Any ideas what I'm doing wrong? Also if anyone knows how I could use fingerId in place of GetTouch(0) that would be wonderful.
Answer by zharik86 · Feb 24, 2014 at 07:24 AM
So, your part of a code is quite correct. But on PC you won't be able to see it as in the Unity emulator the function Input.GetTouch() doesn't give out any values. Therefore your code can be checked only on the emulator from Eclipse or on the real device. Concerning operation with an event of touch and use of fingerId watch my pregoing response. There in case of the contact beginning (TouchPhase.Began it is just necessary to skid in certain int a variable finger number - fingerId - and already further to work with it and when the finger is taken away to do variable value, for example,-1). If there are questions, ask. I hope it to you will help.