Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

279
Views
Button.onClick.AddListener() no funciona según lo previsto

He estado luchando con esto durante el último par de horas. Puedo acceder y editar las propiedades del botón, pero la función onClick.AddListener() no funciona. Aquí está mi código:

 GameObject gameObject; gameObject = Resources.Load("Prefabs/MenuOption") as GameObject; gameObject.GetComponent<Image>().sprite = Resources.Load<Sprite>(option.imgPath); Button button = gameObject.GetComponent<Button>(); // Testing to see if I can change button properties (works) ColorBlock colorss = button.colors; colorss.highlightedColor = Color.magenta; button.colors = colorss; // This does not work button.onClick.AddListener(() => Test(button)); button.onClick.AddListener(() => { Debug.Log("click"); }); Instantiate(gameObject, pos, new Quaternion(), GameObject.Find("Canvas").transform);

Y aquí hay una instancia del prefabricado: imagen

Si alguien sabe que estoy haciendo mal, se lo agradeceria mucho.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Suscribirse al evento onClick en el objeto del juego instanciado (no en el objeto del juego que usa para instanciar otro objeto) debería resolver su problema.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!