Quantcast
Channel: Questions in topic: "script referencing"
Viewing all articles
Browse latest Browse all 41

How do you refference SetActive (true) from another script?

$
0
0
I'm using 2 scripts. One for the SetActive PauseMenu.cs public void Start() { PauseUI.SetActive (false); } //Pause Menu Trigger public void Update() { if (Input.GetButtonDown ("Pause")) { paused = !paused; } if (paused) { PauseUI.SetActive (true); Time.timeScale = 0; //pause menu btns ResumeBtn.SetActive (true); RestartBtn.SetActive (true); OptionsBtn.SetActive (true); QuitBtn.SetActive (true); } if (!paused) { PauseUI.SetActive (false); Time.timeScale = 1; OptionsMenuUI.SetActive (false); SoundMenuUI.SetActive (false); } } The script that will be calling it is ChangeMusic.cs using UnityEngine; using System.Collections; public class ChangeMusic : MonoBehaviour { public AudioClip level2Music; public AudioClip level1Music; public AudioClip gameOverMusic; public AudioClip pauseMusic; //new code public AudioSource source; public AudioSource pausemusic; void Awake () { source = GetComponent(); pausemusic = GetComponent (); } void Start () { } void OnLevelWasLoaded(int level) { if (level == 1) { source.clip = level2Music; source.Play (); } if (level == 0) { source.clip = level1Music; source.Play (); } } //new code public void PlayPauseMusic(AudioClip clip) { if (GetComponent().PauseUI.activeInHierarchy == true) { source.clip = pauseMusic; source.Play (); Debug.Log ("PauseUI has been checked as set active true"); } if (GetComponent().PauseUI.activeInHierarchy == false) { source.clip = level2Music; source.Play (); Debug.Log ("PauseUI has been checked as set active false"); } } public void PausePauseMusic(AudioClip clip) { source.clip = pauseMusic; source.Stop (); source.clip = level2Music; source.Play (); } } Please provide an example of code. I always get trolled by coders giving vague directions as if they get a kick out of pretending to help but not really helping. Thanks in advance!

Viewing all articles
Browse latest Browse all 41

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>