GameJam Progress Day 2
This commit is contained in:
32
Assets/Scripts/UI/ToggleMusic.cs
Normal file
32
Assets/Scripts/UI/ToggleMusic.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ToggleMusic : MonoBehaviour
|
||||
{
|
||||
|
||||
private MusicManager musicManager;
|
||||
private AudioSource audioSource;
|
||||
public Material greenMat, redMat;
|
||||
public Renderer buttonVisuals;
|
||||
public AudioClip clickSound;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
this.audioSource = GetComponent<AudioSource>();
|
||||
this.musicManager = GameObject.Find("/BackgroundMusic").GetComponent<MusicManager>();
|
||||
bool audioState = this.musicManager.musicEnabled;
|
||||
|
||||
this.buttonVisuals.material = audioState ? this.greenMat : this.redMat;
|
||||
}
|
||||
|
||||
void OnMouseDown()
|
||||
{
|
||||
bool newState = this.musicManager.ToggleMusic();
|
||||
|
||||
this.buttonVisuals.material = newState ? this.greenMat : this.redMat;
|
||||
this.audioSource.pitch = newState ? 1.5f : .75f;
|
||||
this.audioSource.PlayOneShot(this.clickSound);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user