- Home /
How to make a simple touch on iPhone ?
Hi guys,
I am struggling since a few days to make a simple touch on iPhone work like a gui.Button. I would like the touch to be from within a Rect, and the touch should launch a function.
So far i had that, wich never worked :
var Rect1 = Rect(95,24,83,130);
// first
if ( Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began){
if(Rect1.Contains(Vector2(Input.GetTouch(0).position.x,Input.GetTouch(0).position.y ))) {
Comparer(1);
} }
// second
var count = Input.touchCount;
for(var i : int = 0;i < count; i++){
var touch : Touch = Input.GetTouch(i);
if ( Rect1.Contains( touch.position ) ){
Comparer(1);
}
}
// third
var count = Input.touchCount;
for (var i =0; i < Input.touchCount; ++i){
if (Input.GetTouch(i).phase == TouchPhase.Ended){
if(Rect1.Contains(Vector2(Input.GetTouch(i).position.x,Input.GetTouch(i).position.y ))) {
Comparer(1);
}
}
}
I would like to understand why it dont work, and what i should do to have this simple GUI.Button like Touch, in a rect with just one touch.
thank you,
Paradoks
Your answer
![](https://koobas.hobune.stream/wayback/20220613100442im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Question about Unity Touch Interface For Android 1 Answer
How do Iake an object touch interactive 1 Answer
Degree from point? 2 Answers
HELP first person controller setup iphone/android 2 Answers
touch control problem 0 Answers