Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Need help with button click

Discussion in 'UGUI & TextMesh Pro' started by geekchick25, Mar 18, 2019.

  1. geekchick25

    geekchick25

    Joined:
    Aug 11, 2018
    Posts:
    13
    Hi, newbie here. I have this UI, yes it's ugly :)

    upload_2019-3-18_9-24-32.png

    The way it works is when you click on 'a' in the bottom in the brown it's supposed to show buttons 'ka' and 'a' which are hidden at start. When you click on 'e' in the bottom in brown it's supposed to show buttons 'ke' and 'e', which it does. Here's the problem. When you go back to 'a' it doesn't show 'ka' and 'a', rather 'ke' and 'e', it just stays on the same one. How do I change it so you can go back and forth between a,e,i,o,u at the bottom in brown? My code and screenshots of inspector are below:



    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class LongKOneSequencing : MonoBehaviour
    7. {
    8.  
    9.     public Button buttonLong1K_a;
    10.     public Button buttonLong1K_aa;
    11.     public Button buttonLong1K_Ka;
    12.  
    13.     public Button buttonLong1K_e;
    14.     public Button buttonLong1K_ee;
    15.     public Button buttonLong1K_Ke;
    16.  
    17.     // Method to Start A
    18.     public void StartA()
    19.     {
    20.         Button btn = buttonLong1K_a.GetComponent<Button>();
    21.         btn.onClick.AddListener(OnClickA);
    22.     }
    23.  
    24.     public void OnClickA()
    25.     {
    26.         //Debug.Log("You have clicked the button!");
    27.         buttonLong1K_aa.gameObject.SetActive(true);
    28.         buttonLong1K_Ka.gameObject.SetActive(true);
    29.     }
    30.  
    31.     // Method to Start E
    32.     public void StartE()
    33.     {
    34.         Button btn = buttonLong1K_e.GetComponent<Button>();
    35.         btn.onClick.AddListener(OnClickE);
    36.     }
    37.  
    38.     public void OnClickE()
    39.     {
    40.         //Debug.Log("You have clicked the button!");
    41.         buttonLong1K_ee.gameObject.SetActive(true);
    42.         buttonLong1K_Ke.gameObject.SetActive(true);
    43.     }
    44.  
    45.  
    46. }
    Here's a screenshot of my game object with inspector:

    upload_2019-3-18_9-24-19.png

    Here's my buttonLongK1_a click():

    upload_2019-3-18_9-25-38.png

    Here's my buttonLongK1_e click():

    upload_2019-3-18_9-26-46.png
     

    Attached Files: