ZWN_DontDestroy.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /// <summary>
  2. /// ZWN
  3. ///跳转场景不删除
  4. /// 20220216
  5. /// </summary>
  6. using System.Collections;
  7. using UnityEngine;
  8. using UnityEngine.SceneManagement;
  9. public class ZWN_DontDestroy : MonoBehaviour
  10. {
  11. //public GameObject ZWN_Dont_pc; //预制体(不销毁的物体(做成预制体))
  12. public GameObject ZWN_Dont_android; //预制体(不销毁的物体(做成预制体))
  13. private static bool isHave = false;
  14. private GameObject ZWN_Dont_Clone;//克隆的不销毁物体
  15. void Awake()
  16. {
  17. if (!isHave)
  18. {
  19. ZWN_Dont_Clone = GameObject.Instantiate(ZWN_Dont_android, transform.position, transform.rotation);
  20. isHave = true;
  21. }
  22. DontDestroyOnLoad(ZWN_Dont_Clone);//切换场景不销毁ZWN_Dont_Clone
  23. SceneManager.LoadSceneAsync(1);
  24. }
  25. /* private void Start()
  26. {
  27. StartCoroutine(LoadScene());
  28. }
  29. IEnumerator LoadScene()
  30. {
  31. yield return new WaitForSeconds(2f);
  32. SceneManager.LoadSceneAsync(1);
  33. }*/
  34. }