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();
}
}
}
這是選單的視頻,不起作用
https://www.youtube.com/watch?v=gfNOi86lbxI&ab_channel=GhiocelGames
音樂“Muzic?”的選項不會關閉。
其他選項不考慮代碼中使用的布爾變數,并且一開始不會在打開時關閉,正如您在視頻中看到的那樣
我想為我的游戲進行設定。
uj5u.com熱心網友回復:
我在你的 bool 之間看到的唯一區別是你在將 musicabool 設定為 true 后立即將其變為 false,而其他 bool 沒有那行代碼,它能解釋你的問題嗎?該行:“musicabool = !musicabool”
uj5u.com熱心網友回復:
讓它作業,通過用 setactive 替換啞色的東西并做一些調整
uj5u.com熱心網友回復:
我認為這應該有效:
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class SettingsScript : MonoBehaviour
{
public GameObject Muzica, Oftat, SFX, Fullscreen, VolumObject;
public bool MuzicaBool = true, OftatBool, SFXBool = true, FullscreenBool = true;
public float VolumFloat = 1f;
public AudioSource on, 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()
{
MuzicaBool = !MuzicaBool;
Muzica.SetActive(MuzicaBool);
PlaySound(MuzicaBool);
UnityEngine.Debug.Log("Muzica");
}
public void OftatOn()
{
OftatBool = !OftatBool;
Oftat.SetActive(OftatBool);
PlaySound(OftatBool);
UnityEngine.Debug.Log("Oftat");
}
public void SFXOn()
{
SFXBool = !SFXBool;
SFX.SetActive(SFXBool);
PlaySound(SFXBool);
UnityEngine.Debug.Log("SFX");
}
public void FullscreenOn()
{
FullscreenBool = !FullscreenBool;
Fullscreen.SetActive(FullscreenBool);
PlaySound(FullscreenBool);
UnityEngine.Debug.Log("Fullscreen");
}
//A method to play the 'on' or 'off' sound
void PlaySound(bool onBool)
{
if(onBool)
on.Play();
else
off.Play();
}
}
我也做了一些“優化”,但我不是專家,所以請隨時糾正我,哈哈
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/537189.html
