Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by heeelp5 · Dec 06, 2015 at 06:41 AM · c#animationanimatorlong

Unassigned Reference Exception

How in the !@#$ did Unity make this work

'm tyring to activate a timed animation through code when you click on a button. I decided to look at some assets on the assets store and found a UI example for me to use in doing this so. Unfortunately the asset was outdated, just a tad bit. so I started this anyway. By reading the commets that Unity's guys left I understood what was going on. except for one part. They used the Invoke parameter to activate the animation when the button is clicked. What I don't understand is how the defined the clip within the canvas of the whole thing and having the button activate just the menu to dissappear. I modified a little bit (take some stuff out combined a few code so most of the button codes like UnPause() would be with the buttons class and such.) Here is my setup if that helps.

 using UnityEngine;
 using System.Collections;
 
 public class Buttons : MonoBehaviour
 {
     public int sceneToStart = 1;                                        //Index number in build settings of scene to load if changeScenes is true
     public bool changeScenes;                                            //If true, load a new scene when Start is pressed, if false, fade out UI and continue in single scene
 
 
     [HideInInspector]
     public bool inMainMenu = true;
     [HideInInspector]
     public Animator animColorFade;                  //Reference to animator which will fade to and from black when starting game.
     [HideInInspector]
     public Animator animMenuAlpha;                  //Reference to animator that will fade out alpha of MenuPanel canvas group
     [HideInInspector]
     public AnimationClip fadeColorAnimationClip;        //Animation clip fading to color (black default) when changing scenes
     [HideInInspector]
     public AnimationClip fadeAlphaAnimationClip;        //Animation clip fading out UI elements alpha//If true, pause button disabled in main menu (Cancel in input manager, default escape key)
 
 
 
     private ShowPanels showPanels;                                        //Reference to ShowPanels script on UI GameObject, to show and hide panels
     private bool isPaused;
 
     void Awake()
     {
        
         //Get a reference to ShowPanels attached to UI object
         showPanels = GetComponent<ShowPanels>();
          
     }
 
 
     //start button W/Animations
     public void StartButtonClicked()
     {
         //If changeScenes is true, start fading and change scenes halfway through animation when screen is blocked by FadeImage
         if (changeScenes)
         {
             //Use invoke to delay calling of LoadDelayed by half the length of fadeColorAnimationClip
             Invoke("LoadDelayed", fadeColorAnimationClip.length * .5f);
             
             //Application.LoadLevel(sceneToStart);
             //Set the trigger of Animator animColorFade to start transition to the FadeToOpaque state.
             animColorFade.SetTrigger("fade");
 
         }
 
         //If changeScenes is false, call StartGameInScene
         else
         {
             //Call the StartGameInScene function to start game without loading a new scene.
             StartGameInScene();
         }
 
     }
     public void LoadDelayed()
     {
         //Pause button now works if escape is pressed since we are no longer in Main menu.
         inMainMenu = false;
 
         //Hide the main menu UI element
         showPanels.HideMenu();
 
         //Load the selected scene, by scene index number in build settings
         Application.LoadLevel(sceneToStart);
     }
     public void StartGameInScene()
     {
         inMainMenu = false;
 
         animMenuAlpha.SetTrigger("fade");
 
         Invoke("HideDelayed", fadeAlphaAnimationClip.length);
 
 
         Debug.Log("Game started in same scene! Put your game starting stuff here.");
 
 
     }
     public void HideDelayed()
     {
         //Hide the main menu UI element
         showPanels.HideMenu();
     }
 
     //pause/excButton *move to Player Controller
     void Update()
     {
         if (Input.GetKeyDown(KeyCode.Escape) && !isPaused && !inMainMenu)
         {
             //call pause function
             DoPause();
         }
         //if the button is pressed and the game is paused and not in main menu 
         else if (Input.GetKeyDown(KeyCode.Escape) && isPaused && !inMainMenu)
         {
             //call unpause function
             UnPause();
         }
     }
     public void DoPause()
     {
         isPaused = true;
         Time.timeScale = 0;
         showPanels.ShowPause();
     }
     public void UnPause()
     {
         isPaused = false;
         Time.timeScale = 1;
         showPanels.HidePause();
     }
 
     //Exit Button
     public void Quit()
     {
 #if UNITY_STANDALONE
         Application.Quit();
 #endif
 
 #if UNITY_EDITOR
         UnityEditor.EditorApplication.isPlaying = false;
 #endif
     }
 }

Here's his if you wanna help me compare the two and figure out why his AnimColorFade and many animators and animation vars aren't getting the Unassigned Reference Exception deal.(modified(comments)and music in his scripts):

 using UnityEngine;
 using System.Collections;
 using UnityEngine.Audio;
 
 
 public class StartOptions : MonoBehaviour {
 
 
 
     public int sceneToStart = 1;                                        //Index number in build settings of scene to load if changeScenes is true
     public bool changeScenes;                                            //If true, load a new scene when Start is pressed, if false, fade out UI and continue in single scene
     //public bool changeMusicOnStart;                                        //Choose whether to continue playing menu music or start a new music clip
     //public int musicToChangeTo = 0;                                        //Array index in array MusicClips to change to if changeMusicOnStart is true.
 
 
     [HideInInspector] public bool inMainMenu = true;                    //If true, pause button disabled in main menu (Cancel in input manager, default escape key)
     [HideInInspector] public Animator animColorFade;                     //Reference to animator which will fade to and from black when starting game.
     [HideInInspector] public Animator animMenuAlpha;                    //Reference to animator that will fade out alpha of MenuPanel canvas group
     [HideInInspector] public AnimationClip fadeColorAnimationClip;        //Animation clip fading to color (black default) when changing scenes
     [HideInInspector] public AnimationClip fadeAlphaAnimationClip;        //Animation clip fading out UI elements alpha
 
 
     //private PlayMusic playMusic;                                        //Reference to PlayMusic script
     //private float fastFadeIn = .01f;                                    //Very short fade time (10 milliseconds) to start playing music immediately without a click/glitch
     private ShowPanels showPanels;                                        //Reference to ShowPanels script on UI GameObject, to show and hide panels
 
     
     void Awake()
     {
         //Get a reference to ShowPanels attached to UI object
         showPanels = GetComponent<ShowPanels> ();
 
         //Get a reference to PlayMusic attached to UI object
         //playMusic = GetComponent<PlayMusic> ();
     }
     
     //if anims are in to fade
     public void StartButtonClicked()
     {
         //If changeMusicOnStart is true, fade out volume of music group of AudioMixer by calling FadeDown function of PlayMusic, using length of fadeColorAnimationClip as time. 
         //To change fade time, change length of animation "FadeToColor"
         /*if (changeMusicOnStart) 
         {
             playMusic.FadeDown(fadeColorAnimationClip.length);
             Invoke ("PlayNewMusic", fadeAlphaAnimationClip.length);
         }*/
 
         //If changeScenes is true, start fading and change scenes halfway through animation when screen is blocked by FadeImage
         if (changeScenes) 
         {
             //Use invoke to delay calling of LoadDelayed by half the length of fadeColorAnimationClip
             Invoke ("LoadDelayed", fadeColorAnimationClip.length * .5f);
 
             //Set the trigger of Animator animColorFade to start transition to the FadeToOpaque state.
             animColorFade.SetTrigger ("fade");
         } 
 
         //If changeScenes is false, call StartGameInScene
         else 
         {
             //Call the StartGameInScene function to start game without loading a new scene.
             StartGameInScene();
         }
 
     }
 
     //to start the game or stop
     public void LoadDelayed()
     {
         //Pause button now works if escape is pressed since we are no longer in Main menu.
         inMainMenu = false;
 
         //Hide the main menu UI element
         showPanels.HideMenu ();
 
         //Load the selected scene, by scene index number in build settings
         Application.LoadLevel (sceneToStart);
     }
 
 
     public void StartGameInScene()
     {
         inMainMenu = false;
 
         animMenuAlpha.SetTrigger ("fade");
         
         Invoke("HideDelayed", fadeAlphaAnimationClip.length);
 
         
         Debug.Log ("Game started in same scene! Put your game starting stuff here.");
 
 
     }
 
 
     /*public void PlayNewMusic()
     {
         //Fade up music nearly instantly without a click 
         playMusic.FadeUp (fastFadeIn);
         //Play music clip assigned to mainMusic in PlayMusic script
         playMusic.PlaySelectedMusic (musicToChangeTo);
     }*/
 
     public void HideDelayed()
     {
         //Hide the main menu UI element
         showPanels.HideMenu();
     }
 }
 



Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

49 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do i code for a animation in unity for clones of the SAME object? 0 Answers

How to make animation to make other animation? 0 Answers

Advice on how to proceed/Which technique to use [Weapon Animation] 0 Answers

How do I modify animation parameters from script (C#) 1 Answer

OnMouseExit triggering when its not supposed to 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges