Search Unity

DontDestroyOnLoad

Discussion in 'Editor & General Support' started by jowin4ever, Apr 8, 2018.

  1. jowin4ever

    jowin4ever

    Joined:
    Jul 9, 2017
    Posts:
    5
    Hi
    I have some error Unity after use 5.1 change to 5.6.3f
    All my image , etc are missing:

    InvalidOperationException: The following game object is invoking the DontDestroyOnLoad method: AudioManager. Notice that DontDestroyOnLoad can only be used in play mode and, as such, cannot be part of an editor script.
    BaseManager.OnEnable () (at Assets/Bubble Shooter Pet Match 3 Completed/Scripts/Managers/BaseManager.cs:37)


    --------------------------------------------------------------------------------------------------------------------------------

    using UnityEngine;
    using System.Collections;

    // Is the parent Base manager all other Managers will use AudioClips or other data from
    public class BaseManager : ScriptableObject
    {

    // instance of class (Singleton)
    public static BaseManager instance = null;

    // audio clips to play looped and fade in/out
    public AudioClip menuMusic;
    public static GameObject globalMenuMusic;
    public AudioClip gameMusic;
    public static GameObject globalGameMusic;

    // our fade animation clip
    public AnimationClip fadeClip;

    // audio clips to play one time
    public AudioClip sfxButton;
    public AudioClip sfxBomb;
    public AudioClip sfxSwap;
    public AudioClip sfxTouched;
    public AudioClip sfxDrop;
    public AudioClip sfxReadyGo;
    public AudioClip sfxThrow;
    public AudioClip sfxVictory;
    public AudioClip sfxFailed;

    // declare instance
    void OnEnable()
    {
    if (instance == null)
    {
    instance = this;
    DontDestroyOnLoad(this);
    }
    }

    public static BaseManager GetInstance()
    {
    return instance;
    }
    }