得到背景音乐选框
赋值
赋值
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//2.获得UI
using UnityEngine.UI;
public class UIManager : MonoBehaviour
{
//6.调用
public static UIManager _instance;
//1.获得UItext
public Text shootNumText;
public Text scoreText;
//4.初始化
public int shootNum = 0;
public int score = 0;
//7.得到背景音乐选框
public Toggle musicToggle;
public AudioSource musicAudio;
private bool musicOn = true;
//6.调用
private void Awake()
{
_instance = this;
}
//5.在update中实时更新数据
private void Update()
{
shootNumText.text = shootNum.ToString();
scoreText.text = score.ToString();
//7.调用音乐转换器
MusicSwitch();
}
//7.音乐开关
private void MusicSwitch()
{
if (musicToggle.isOn == false)
{
musicOn = false;
musicAudio.enabled=false;
}
else{
musicOn = true;
musicAudio.enabled=true;
}
}
//3.方法
public void AddShootNum()
{
shootNum += 1;
}
public void AddScore()
{
score += 1;
}
}
标签:unity3D,false,16,void,private,musicAudio,音效,using,public
From: https://www.cnblogs.com/flyall/p/17181409.html