I have a pause popup panel in a different scene that gets loaded on top of the game scene through LoadSceneMode.Additive. I have made custom animations but whenever I try to play them I keep getting null reference error but whenever I test it in the scene with the popup panel it works.
Also if I made the time scale to 0 when the pause popup opens, how can I still keep playing the popup intro animation?
Heres what I have. I just took the area the code where I’m referencing the animation.
void Start()
{
_anim = GameObject.FindGameObjectWithTag("Pause").GetComponent<Animator>();
}
IEnumerator Intro()
{
_anim.SetBool("Intro",true);
yield return new WaitForSeconds(clip.length);
_anim.SetBool("Intro",false);
yield return null;
}
Are you sure your tag is the same as the object? Also what is the point in making it a corentine if it only runs once when you pause there should be no problem making it a normal void function.
Yea its tagged. The problem is the object the script is referencing is inside a different scene. How can I access the gameobject in a different scene. I’m using coroutine because for outro animation I think I need it because i want the animation to finish and then close the popup. For intro it doens’t really matter your right.
I do not think its possible to access a gameobject in another scene from the current open scene. You could try something like instantiate the gameobject in your new scene before the animation runs.
Ok thanks. i’ll give that a try.
Thanks for the help mumbot. This is what I came up with and it works.
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class ButtonManagerPause : ButtonManager
{
public Animator anim;
void Start ()
{
//make it not be affected by Time.Timescale = 0
anim.updateMode = AnimatorUpdateMode.UnscaledTime;
anim.SetBool("Intro", true);
}
public new void UnloadScene(string scene)
{
StartCoroutine("Outro", scene);
}
IEnumerator Outro(string scene)
{
Time.timeScale = 1f;
AudioListener.volume = 1;
_IsPauseActive = false;
anim.SetBool("Outro", true);
//get the animation length of the Outro animation
yield return new WaitForSeconds(anim.GetCurrentAnimatorStateInfo(0).length);
SceneManager.UnloadScene(scene);
yield return null;
}
}