Vlad Ilisan
Vlad Ilisan

Reputation: 73

Make a pop up panel asking if I am sure I want to buy a specific item in Unity

Like in the title I want to make a panel when I press a button for buying a specific item to pop up and ask me if I am sure I want to buy that item and if I press yes to buy it. There are going to be a lot of items and I don't want to make a separate panel for every one.

Upvotes: 1

Views: 40

Answers (1)

Technivorous
Technivorous

Reputation: 1712

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Deny : MonoBehaviour {
    public string mess = "Are you sure?";
Rect body;

public vois Start(){
body= new Rect(Screen.width / 2 - 150, Screen.height / 2 - 32, 300, 64)
}

    private void OnGUI()
    {
        GUI.depth = -3;
        GUI.Box(body, mess);
        GUI.Button(new Rect(body.x+5,body.y+body.height-50, 110,46 ),"Yes"){
//player clicked yes handle it
 //after your work : Destroy(this.gameObject);
};
  GUI.Button(new Rect((body.x+body.width)-115,body.y+body.height-50, 110,46 
),"no"){
//player clicked no handle it
//after your work : Destroy(this.gameObject);
};

    }
}

put this on an empty item, and make a prefab. then when you want to use it instantiate ur prefab

Upvotes: 0

Related Questions