using UnityEngine;
using UnityEngine.SceneManagement;
public class SceneTransition : MonoBehaviour
{
[SerializeField] private string sceneName;
[SerializeField] public string password;
private void OnTriggerEnter2D(Collider2D other)
{
if(other.CompareTag("Player"))
{
PlayerMovement.Instance.scenePassword = password;
SceneManager.LoadSceneAsync(sceneName);
}
}
}
创建一个精灵,添加碰撞触发,挂载此脚本,上面写上要传送到的场景名字,下面是唯一的密码,这个是入口,拖入图片,并放在你想当作进门的地方,
```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Entrance : MonoBehaviour
{
public string entrancePassword;
private void Start()
{
if(PlayerMovement.Instance.scenePassword == entrancePassword)
{
PlayerMovement.Instance.transform.position = transform.position;
}
else
{
Debug.LogError("Wrong PW. Please Check your Scene name and Entrance password");
}
}
}
创建一个空物体挂在上面的精灵下,并挂上上面的脚本,写上角色所在地图名字,这是出口,并放在你想出现的地方