1.给门加上触发器
using UnityEngine;
using UnityEngine.SceneManagement;
public class DoorTriger : MonoBehaviour
{
bool ist = false;
private void OnTriggerEnter(Collider other)
{
if(other.CompareTag("Player"))
{
ist = true;
}
}
private void OnTriggerExit(Collider other)
{
if (other.CompareTag("Player"))
{
ist = false;
}
}
void Update()
{
if(Input.GetKeyDown(KeyCode.Q) && ist)
{
SceneManager.LoadScene("LoadScene");
}
}
}
2.做一个Load场景 ,内有TimeLine(相机动画+开门动画)
![](https://img-blog.csdnimg.cn/direct/76dac3336f75429b9e0587ea452c8a30.png)
3.异步加载代码,通过门触发先加载Load场景,TimeLine播放完毕到达目标场景
using System.Collections;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.SceneManagement;
public class LoderSceneManager : MonoBehaviour
{
PlayableDirector director;
void Start()
{
director= GetComponent<PlayableDirector>();
StartCoroutine(LoadScene());
}
IEnumerator LoadScene()
{
AsyncOperation operation;
operation = SceneManager.LoadSceneAsync("NextScene");
operation.allowSceneActivation = false;
while(!operation.isDone)
{
if(operation.progress>=0.9f)
{
director.Play();
break;
}
yield return null;
}
while(director.state==PlayState.Playing)
{
yield return null;
}
operation.allowSceneActivation= true;
yield return null;
}
}
4. 效果
![](https://img-blog.csdnimg.cn/direct/1d141ab50c1f4e6e9dd51ccb75dc426a.gif)