我的游戏玩法是这样的,我希望我的场景执行这个流程:
- 场景 1 -> 场景 2 -> 场景 1
- 场景 1 -> 场景 3 -> 场景 1
- 场景 1 -> 场景 4 -> 场景 1
- 场景 1 -> 场景 5 -> 场景 1
我有 4 个不同的触发器导致 4 个不同的场景。但是每次我启动 Scene1 时,第一次与任何触发器接触时都会被实例化的场景,无论下一个触发器指向哪个场景,都会再次实例化。我在这里做错了什么?如何解决?
您在上图中看到的对撞机是 4 个触发器。每个触发器的代码如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class enter4kWorld : MonoBehaviour {
//Orb Transform
public GameObject targetGO;
public GameObject otherTargetGO1;
public GameObject otherTargetGO2;
public GameObject otherTargetGO3;
public Animator LightBurst;
public GameObject Processor;
public GameObject SceneExitGO;
public float CountDownTimer;
// Use this for initialization
void Start () {
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "GameController")
{
Debug.Log("Teleporter works");
SceneExitGO.SetActive(true);
targetGO.SetActive(true);
otherTargetGO1.SetActive(false);
otherTargetGO2.SetActive(false);
otherTargetGO3.SetActive(false);
}
}
// Update is called once per frame
void Update()
{
if (SceneExitGO.activeSelf)
{
//float step = speed * Time.deltaTime;
//transform.position = Vector3.MoveTowards(transform.position, target.position, step);
CountDownTimer -= Time.deltaTime;
if (Processor.transform.position.y <= 9f)
{
Processor.transform.Translate(Vector3.up * Time.deltaTime * 1.5f, Space.World);
}
if (CountDownTimer <= 4.5)
{
LightBurst.SetTrigger("TriggerLightBurst");
}
if (CountDownTimer <= 0)
{
ChangeScene();
CountDownTimer = 0;
}
}
}
public void ChangeScene()
{
SceneManager.LoadScene("Scene2");
//SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}