- Home /
Three ingame buttons conflict with each other on iOS
I'm just learning Unity and I would like to ask a pretty simple question. I have 3 buttons in my class and they work strange. Here's how I create them:
void OnGUI() {
if (GUI.RepeatButton(new Rect(10, 440, 120, 180), @"Left"))
//Debug.Log("Clicked left");
goLeft();
if (GUI.RepeatButton(new Rect(820, 440, 120, 180), "Right"))
//Debug.Log("Clicked right");
goRight();
if (GUI.Button(new Rect(410, 440, 200, 200), "Shoot"))
TapFunction();
}
And they trigger 3 methods as you can see:
void goLeft() {
Debug.Log("Clicked left");
if (transform.position.x < -20) {
//get new speed
speed = Random.Range(8f,12f);
transform.position = new Vector3( 20f, transform.position.y, transform.position.z );
}
transform.Translate(0, 0, -speed * Time.deltaTime);
}
void goRight() {
Debug.Log("Clicked right");
if (transform.position.x > 20) {
//get new speed
speed = Random.Range(8f,12f);
transform.position = new Vector3( -20f, transform.position.y, transform.position.z );
}
transform.Translate(0, 0, speed * Time.deltaTime);
}
void TapFunction() {
GameObject bombObject = (GameObject)Instantiate(bombPrefab);
bombObject.transform.position = this.gameObject.transform.position;
}
The peculiar thing is that when I touch on the button and anywhere else on the screen with another finger, the button I was holding my finger on becomes inactive. When touching another button while holding another one, the 2nd button (one with the type GUI.Button
) is fired.
How can I make 2 GUI.RepeatButton
s cancel each other (so when I press on the first one while pressing on the second, the first one would release the touch?) and the GUI.Button
not get fired on touch with another button?
Your answer
![](https://koobas.hobune.stream/wayback/20220613091139im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
iPhone Resolution Screen Switch 0 Answers
Mini Mac - Can this Compile Unity? 2 Answers
Unity modules for iOS? 1 Answer
Game crashing on iOS after 3 second load of new scene. (How can I optimise loading) 0 Answers
iPhone Controller Asset 0 Answers