Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

One Panel , two ui button

Discussion in 'Scripting' started by ArshidaGames, Jun 26, 2019.

  1. ArshidaGames

    ArshidaGames

    Joined:
    Feb 9, 2019
    Posts:
    93
    Hello,
    i have 2 ui buttons called:

    ui Button1 : new game
    ui Button2 :continue

    i have also one Panel in the scene. In this Panel i have created two ui texts . these texts are also called :

    ui Text 1 : new game
    ui Text 2 :continue

    what i need to do is , when i click on ui button new game , the panel gets open and shows ui text new game and vice versa.

    i have created a script and attached it to the canvas, but i dont know how to do the coding correctly. i would like to ask for help. thanks.

    Code (CSharp):
    1. public class UiPanelText : MonoBehaviour
    2. {
    3.  
    4.  
    5.  
    6.  
    7.     void Start()
    8.     {
    9.        
    10.     }
    11.  
    12.     void Update()
    13.     {
    14.        
    15.     }
    16. }
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,745
    To do coding correctly, you open up a text editor and type appopriate commands avoiding misstypes and syntax errors. After code has compiled, it considered correct.
     
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,744
    Perhaps you should try going through Unity's UI scripting tutorials. After going through those, if there are still parts of the process you don't understand, you will at least be able to ask a specific question.
     
  4. ArshidaGames

    ArshidaGames

    Joined:
    Feb 9, 2019
    Posts:
    93
    Code (CSharp):
    1.     public GameObject LoadScenePanel;
    2.  
    3.     public void OpenLoadScenePanel()
    4.     {
    5.      
    6.         NewGame.enabled = true;
    7.         Continiue.enabled = false;
    8.     }
    9.  
    10.     public void OpenContiniueScenePanel()
    11.     {
    12.    
    13.         NewGame.enabled = false;
    14.         Continiue.enabled = true;
    15.     }
    i created two functions for both of ui buttons. then in the scene editor , i made both of the ui texts active. now each time the panel gets open, it shows the correct ui text . i dont know if there is a better solution for that. if you have any idea please tell me . thanks.
     
  5. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,745
    If you plan to have more panels, it may be good idea to add them to list or array so you can iterate over all panels enabling the desired one and disabling all others.
     
  6. Thibault-Potier

    Thibault-Potier

    Joined:
    Apr 10, 2015
    Posts:
    206