Can I not Use Void Start this way with 2 animation references?
I'm finding it will only read the animation reference on top and not the one on the bottom?
 using UnityEngine;
 using System.Collections;
 
 public class ApproachWarningPanelManager : MonoBehaviour {
 
     float volume = 0.3f; //Clip Volume Setting
 
     //Reference to Animations
     public GameObject ApproachWarningPanelAni;
     public GameObject RadarSweepAni;
     
     //Audio Clip References
     public AudioClip WindowSlideInFX;
     public AudioClip WindowSlideOutFX;
     
     
     //animator reference
     private Animator anim;
     private Animator anim2Radar;
 
 
     void Start () {
         //get the animator component
         anim2Radar = RadarSweepAni.GetComponent<Animator>();
         //disable it on start to stop it from playing the default animation
         anim2Radar.enabled = false;
 
         anim = ApproachWarningPanelAni.GetComponent<Animator>();
         anim.enabled = false;
 
 
         }
 
     // Update is called once per frame
     void Update () {
     
     }
 }
 
Answer by Arshia001 · Dec 04, 2015 at 06:43 PM
I'm guessing the animator is somewhere down the hierarchy and GetComponent is failing to find it... Change your variable declarations to
Animator BlahBlahAnim; Animator YadaYadaAnim;
You can still drag and drop gameobjects on it in the editor, but it'll automatically check for the component and assign it instead of the gameobject itself.
Thanks @Arshia001 but what does this mean ? Animator BlahBlahAnim; Animator YadaYadaAnim;??
Here is how stuff is in the inspector. 


O$$anonymous$$, I'm terrible at explaining stuff. What I meant is, you should change the type of your variables from Gameobject to Animator. That way, you won't need the GetComponent call and you'll always have the Animator component ready. Change
 public GameObject ApproachWarningPanelAni;
 public GameObject RadarSweepAni;
To:
 public Animator ApproachWarningPanelAni;
 public Animator RadarSweepAni;
@Arshia001 O$$anonymous$$ I changed it to that but it does not appear to be disabling the animation?
 using UnityEngine;
 using System.Collections;
 
 public class ApproachWarningPanel$$anonymous$$anager : $$anonymous$$onoBehaviour {
 
     float volume = 0.3f; //Clip Volume Setting
 
     //Reference to Animations
     public Animator ApproachWarningPanelAni;
     public Animator RadarSweepAni;
     
     //Audio Clip References
     public AudioClip WindowSlideInFX;
     public AudioClip WindowSlideOutFX;
     public AudioClip RadarSFX;
 
     private AudioSource RadarSoundFX;
     
     
     //animator reference
     private Animator anim;
     private Animator anim2Radar;
 
 
     void Start () {
         //get the animator component
         anim2Radar = RadarSweepAni.GetComponent<Animator>();
         //disable it on start to stop it from playing the default animation
         anim2Radar.enabled = false;
 
         anim = ApproachWarningPanelAni.GetComponent<Animator>();
         anim.enabled = false;
 
         RadarSoundFX = RadarSweepAni.GetComponent<AudioSource>();
         RadarSoundFX.enabled = false;
         }
 
     //Start Approach Warning Panel Slide In Animation
     public void  StartApprWarnPanelSlideIn(){
         StartCoroutine (ApprWarnPanelSlideIn ());
     }
     
     IEnumerator ApprWarnPanelSlideIn(){
         yield return new WaitForSeconds (0.6f); // wait time
         anim.enabled = true;
         GetComponent<AudioSource>().PlayOneShot(WindowSlideInFX, volume);
         anim.Play("ApprWarnSlideInAni");
         
     }
     
     //Start Approach Warning Panel Slide Out Animation
     public void  StartApprWarnPanelSlideOut(){
         StartCoroutine (ApprWarnPanelSlideOut ());
     }
     
     IEnumerator ApprWarnPanelSlideOut(){
         yield return new WaitForSeconds (0.6f); // wait time
         anim.enabled = true;
         GetComponent<AudioSource>().PlayOneShot(WindowSlideOutFX, volume);
         anim.Play("ApprWarnSlideOutAni");
         
     }
 }
 
Your answer
 
 
             Follow this Question
Related Questions
Void start from current script not disable other script 0 Answers
Keyword 'void' cannot be used in this context, cant figure out what to do 1 Answer
Class array initialization on Start() gives -> Object reference not set to an instance of an object 1 Answer
2D Animation disables Player Controller Script 1 Answer
c# Object reference not set to an instance of an object 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                