Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Fumagago · Nov 06, 2018 at 06:13 AM · unity 5buttonbuttonseventsystem

Change properties of a button by pressing another button in Unity

Good day, I have a problem in Unity that I could not solve, the only thing I want is that by pressing a button to change the image of other 3 buttons, the idea is that I have 30 buttons and if I press any of them, I change the Image property of another 3 buttons depending on the button that you press before. This is the script that I am using:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.EventSystems;
 using UnityEngine.Experimental.UIElements;
 
 public class Controller : MonoBehaviour {
     public Camera cam1, cam2;
     public Sprite[] mayus;
     public AudioClip[] clipLetras;
     public AudioSource fuente;
     public GameObject imagenMayus, imagenMinus, imagenManus;
     new string name;
     public Image imgMayus, imgMinus, imgManus;
 
     // Use this for initialization
     void Start () {
         
         cam2.gameObject.SetActive(false);
     }
     
     // Update is called once per frame
     void Update () {
         
     }
 
     public void MoverCamara()
     {
         name = EventSystem.current.currentSelectedGameObject.name;
         cam1.gameObject.SetActive(false);
         cam2.gameObject.SetActive(true);
 
         //cam1.gameObject.transform.position = cam2.transform.position;
 
         //cam2.gameObject.SetActive(true);
 
        
     }
     public void RegresarMenuLetras()
     {
         cam1.gameObject.SetActive(true);
         cam2.gameObject.SetActive(false);
     }
 
     public void ReproducirClip()
     {
        
 
         for (int x = 0; x < mayus.Length; x++)
         {
            
             if (mayus[x].name == name)
             {
                
                 fuente.clip = clipLetras[x];
                 fuente.Play();
                 
                 Debug.Log("entra " + mayus[x].name);
                 Debug.Log("entra " + name);
                 Debug.Log("entra " + x);
             }
             
         }
         
     }
     public void CambiarBotones()
     {
         
     }
     
     
 }


In the change buttons method, I would like to change the Image property of 3 different buttons.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hectorux · Nov 06, 2018 at 06:01 PM

You could make a class called something like BotonesACambiar and store there the buttons you want to change if you press that button, atach to that button the script (one per button), and finally make a method to change your 3 buttons to the images you wanted. I recomend this because if every button will have therir custom 3 buttons, then is better to assign them manually. A button can have more than one listener to play

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

200 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Where is my OnClick in the button script? 1 Answer

Hi, button.onClick.AddListener makes nothing no error, no adding any listener. Please help 0 Answers

Change mouse button click in existing code to ui button click.,Change the existing code from mouse click to ui buttons. 1 Answer

UI button not working 1 Answer

Unity 5 UI buttons don't respond well with clicks when used in windows standalone with different resolutions. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges