Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

118
Visualizações
How to make one toggle turn off when the other turns on in unity

I am making a 2d game in unity. I am using the UI toggle methods and wish to make one of those turn off when the other one is turned on. The method I have tried is doing the following code below (InfiniteMode and CampaignMode are the names of the two toggles):

if (InfiniteMode.isOn)
    {
        PlayInfinite();
        CampaignMode.onValueChanged.Invoke(false);
    }

    if (CampaignMode.isOn)
    {
        PlayCampaign();
        InfiniteMode.onValueChanged.Invoke(false);
    }

Any help for what I can do to achieve this would be great.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

As far as I understand you want to have two UI Toggles which acts as a group, when one of them is on, the rest of the items are off. In order to do this you can use Toggle Group component from Unity UI. You can find more information on that here: Toggle Group documentation.

If you look at Toggle component there is a Group variable. If you create an empty GameObject inside your Canvas and add Toggle Group component to it and assign that Toggle Group object to all your Toggle's which you want to be a part of that group it should work.

over 4 years ago · Santiago Trujillo Relatório

0

You can add listeners to your toggles like this:

[SerializeField]
private Toggle myToggleVar;

private void Start() {
    // UI event listeners
    myToggleVar.onValueChanged.AddListener(delegate { onToggleExec(); });
}

private void onToggleExec() {
    Debug.Log("Toggled!") //here you need to manipulate your other toggle
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda