S
S
Shameless192021-01-29 21:30:22
Unity
Shameless19, 2021-01-29 21:30:22

Different functionality for prefab buttons?

Oh, my love, that unity knows, save from the desert of despair
The bottom line is that there is a script (conditionally InitScr). It will spawn buttons on the stage with text in them (different in content), and life would be great, but the brain fluid in me cannot figure out how to make it so that when a button is clicked, a certain function is performed corresponding to the button text. Everything that is generated will either hurt performance or hurt the eyes (crutches), and they suffer enough as it is

. This is the soul of the script, if needed:

public class QvText1 : MonoBehaviour
{
  public static int qvest0;
  public static int qvest1;
  public static int qvest2;
  public static int qvest3; // планируется много
  public static int qvest4;
  public static int qvest5;
  public static List<string> qv;
  public GameObject TextObj;
  public GameObject ButtObj;
  public GameObject ContentCanvas;
  private GameObject textInst;
  GameObject buttInst;

  void Start()
  {
    qv = new List<string>();

    if(qvest3 == 1)
     { string  sqvt = "В джунглях живет много необитаемых женщин";QvestApp(sqvt);}
    if(qvest2 == 1)
     { string  sqvt = "И все она жаждет лишь единицу";QvestApp(sqvt);}
    if(qvest1 == 1)
     { string  sqvt = "И нас знаем что это есть";QvestApp(sqvt);}
    if(qvest0 == 1)
     { string sqvt = "Призывать это только не в честь";QvestApp(sqvt);}
  }
 public void Init(string s)
    {
      textInst = Instantiate(TextObj, TextObj.transform.position, Quaternion.identity);
      textInst.transform.SetParent(ContentCanvas.transform, false);
      TextObj.gameObject.GetComponent<Text>().text = s;
    }
void QvestApp(string str)
{
  qv.Add("⦿ " +str);
      buttInst = Instantiate(ButtObj, ButtObj.transform.position, Quaternion.identity);
      buttInst.transform.SetParent(ContentCanvas.transform, false);

      textInst = Instantiate(TextObj, TextObj.transform.position, Quaternion.identity);
      textInst.transform.SetParent(buttInst.transform, false);
      TextObj.gameObject.GetComponent<Text>().text = "⦿ " +str;
}
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question