How do you refference SetActive (true) from another script?
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<AudioSource>();
         pausemusic = GetComponent<AudioSource> ();
 
     }
 
 
     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<PauseMenu>().PauseUI.activeInHierarchy == true) 
         {
             source.clip = pauseMusic;
             source.Play ();
             Debug.Log ("PauseUI has been checked as set active true");
         }
 
         if (GetComponent<PauseMenu>().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!
Answer by KnightRiderGuy · Dec 30, 2016 at 03:39 PM
At the top of you 2nd script add a reference to the first object that has the script like this:
something like:
 //UI Panel Objects
 public GameObject musicPlayerObject;
Then in your script just access it like this:
 musicPlayerObject.SetActive (true);
Your answer
 
 
             Follow this Question
Related Questions
I need to activate a function in another script from a script on a different game object 0 Answers
Problem when acessing a list from another script? (ArgumentOutOfRangeException) 0 Answers
How do I link variables in between two scripts in c# 1 Answer
Why do I keep getting a null reference? Its not null! 0 Answers
Referencing another script error/problem 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                