how to press gui button at the same time??

i have 2 gui buttons…and i want to press it at the same time…how???

using UnityEngine;
using System.Collections;



public class Tap : MonoBehaviour
{
    public Texture2D buttonImage = null;
    public GameObject objectToMove;
   
    private float timer;
   
    void Start()
    {
        timer = 0.0f;
    }
   
    void Update()
    {
        timer += Time.deltaTime;

    }
   
    private  void OnGUI()
    {
        if (timer > 4.0f)
        {
            if (GUI.Button (new Rect(50,350,300,100),buttonImage))
            {
                this.transform.position += new Vector3(-1.0f, 0.0f, 0.0f) ;
            }
            if (timer > 4.0f) {
                if (GUI.Button (new Rect (400, 350, 300, 100), buttonImage)) {
                    this.transform.position += new Vector3 (1, 0, 0);
                }
            }
        }
    }
}

Do you mean tap two buttons at the same time on a touch device?

I haven’t tested the following, but here is the general idea:

using UnityEngine;
using System.Collections;

public class Tap : MonoBehaviour
{
    public Texture2D buttonImage = null;
    public GameObject objectToMove;

    private float timer;

    private readonly Rect firstButtonPosition = new Rect(50,350,300,100);
    private readonly Rect secondButtonPosition = new Rect(400, 350, 300, 100);

    void Start()
    {
        timer = 0.0f;
    }

    void Update()
    {
        timer += Time.deltaTime;

        int touchCount = Input.touchCount;
        for (int i = 0; i < touchCount; ++i)
        {
            var touch = Input.GetTouch(i);
            if (touch.phase == TouchPhase.Began)
            {
                // Get touch point and invert Y-axis.
                var touchPoint = touch.position;
                touchPoint.y = Screen.height - touchPoint.y;

                if (firstButtonPosition.Contains(touchPoint))
                {
                    OnFirstButtonTapped();
                }
                if (secondButtonPosition.Contains(touchPoint))
                {
                    OnSecondButtonTapped();
                }
            }
        }
    }

    private void OnGUI()
    {
        // Here we just draw the buttons without checking for touch input!
        if (timer > 4.0f)
        {
            GUI.Button (firstButtonPosition, buttonImage);
            if (timer > 4.0f)
            {
                GUI.Button (secondButtonPosition, buttonImage);
            }
        }
    }

    private void OnFirstButtonTapped()
    {
        // Tapped first button!
        this.transform.position += new Vector3(-1.0f, 0.0f, 0.0f) ;
    }

    private void OnSecondButtonTapped()
    {
        // Tapped second button!
        this.transform.position += new Vector3 (1, 0, 0);
    }
}

yes :slight_smile:

Assets/Script/Tap.cs(27,55): error CS0117: UnityEngine.TouchPhase' does not contain a definition for Begin’

That is a typo which should have read “TouchPhase.Began”:

Like I said, this code has not been tested :wink: