Home > Blockchain >  Why will turning options on and off not work?
Why will turning options on and off not work?

Time:11-20

using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class SettingsScript : MonoBehaviour
{
    public GameObject Muzica;
    public GameObject Oftat;
    public GameObject SFX;
    public GameObject Fullscreen;
    public GameObject VolumObject;
    public bool MuzicaBool = true;
    public bool OftatBool;
    public bool SFXBool = true;
    public bool FullscreenBool = true;
    public float VolumFloat = 1f;
    public AudioSource on;
    public AudioSource off;
    public static SettingsScript instance;

    void Awake()
    {
        instance = this;
    }

    void Update()
    {
        UnityEngine.Debug.Log(MuzicaBool   " "   OftatBool   " "   SFXBool   " "   FullscreenBool   " "   VolumFloat);
    }

    public void Menu()
    {
        SceneManager.LoadScene("Meniu");
    }

    public void Volum()
    {
        AudioListener.volume = VolumFloat;
    }

    public void MuzicaOn()
    {
        if (MuzicaBool)
        {
            Muzica.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 0);
            MuzicaBool = !MuzicaBool;
        }
        else
        {
            Muzica.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 1);
        }
        MuzicaBool = !MuzicaBool;
        UnityEngine.Debug.Log("Muzica");
        if(MuzicaBool)
        {
            on.Play();
        }
        else
        {
            off.Play();
        }
    }

    public void OftatOn()
    {
        if (OftatBool)
        {
            Oftat.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 0);
        }
        else
        {
            Oftat.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 1);
        }
        OftatBool = !OftatBool;
        UnityEngine.Debug.Log("Oftat");
        if(OftatBool)
        {
            on.Play();
        }
        else
        {
            off.Play();
        }
    }

    public void SFXOn()
    {
        if (SFXBool)
        {
            SFX.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 0);
        }
        else
        {
            SFX.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 1);
        }
        SFXBool = !SFXBool;
        UnityEngine.Debug.Log("SFX");
        if(SFXBool)
        {
            on.Play();
        }
        else
        {
            off.Play();
        }
    }

    public void FullscreenOn()
    {
        if (FullscreenBool)
        {
            Fullscreen.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 0);
        }
        else
        {
            Fullscreen.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 1);
        }
        FullscreenBool = !FullscreenBool;
        UnityEngine.Debug.Log("Fullscreen");
        if(FullscreenBool)
        {
            on.Play();
        }
        else
        {
            off.Play();
        }
    }
}

here's a video of the menu, not working

https://www.youtube.com/watch?v=gfNOi86lbxI&ab_channel=GhiocelGames

The option for music "Muzică", does not turn off.

The other options do not respect the boolean variables used in the code, and at first wont turn off if on, as you can see in the video

I want to make settings for my game.

CodePudding user response:

The only difference I see between your bools is you are instantly turning the musicabool to false right after putting it to true, while the other bools don't have that line of code, could it explain your issue? The line: "musicabool = !musicabool"

CodePudding user response:

Got it working, by replacing the dumb color things with setactive and doing some tweaks

  • Related