Scriptum/Assets/Scripts/ChangeScene.cs

88 lines
2.3 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using System;
2023-01-07 00:39:19 +01:00
using System.Diagnostics;
using Debug = UnityEngine.Debug;
public class ChangeScene : MonoBehaviour
{
float x, y, z;
2023-01-07 00:39:19 +01:00
private Animator myanim;
public void MoveToScene(int sceneID)
{
SceneManager.LoadScene(sceneID);
}
2023-01-07 00:39:19 +01:00
public void MoveToSceneFirst(int sceneID)
{
//Scene current = SceneManager.GetActiveScene();
//Debug.Log(PlayerPrefs.HasKey("HER"));
if (!PlayerPrefs.HasKey("SceneSaved"))
{
SceneManager.LoadScene(5);
}
else
{
SceneManager.LoadScene(sceneID);
}
}
void Start(){
}
2023-01-07 00:39:19 +01:00
private void Awake()
{
}
private void Update()
{
}
private IEnumerator WaitForAnimationAndMoveToScene(float waitTime, Collision2D collision)
{
while (true)
{
yield return new WaitForSeconds(waitTime);
2023-01-07 00:39:19 +01:00
Debug.Log("BEFORE");
collision.gameObject.GetComponent<DoorBehaviour>().ScenetToMoveTo();
2023-01-07 00:39:19 +01:00
Debug.Log("AFTER");
}
}
2022-10-02 18:45:58 +02:00
// method is invoked only when script is assign to the player prefab object
public void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.tag == "SceneTransition")
{
2023-01-10 23:55:41 +01:00
if(collision.gameObject.GetComponent<DoorBehaviour>() != null && !collision.gameObject.GetComponent<DoorBehaviour>().isEnabled)
{
Debug.Log("Door are not enabled");
return;
}
else if (collision.gameObject.GetComponent<AnimatedDoorBehaviour>() != null && !collision.gameObject.GetComponent<AnimatedDoorBehaviour>().isEnabled)
{
Debug.Log("Door are not enabled");
return;
}
2022-10-02 18:45:58 +02:00
collision.gameObject.GetComponent<DoorBehaviour>().ScenetToMoveTo();
}
if(collision.gameObject.tag == "AnimatedDoorSceneTransition")
{
Debug.Log("Starting coroutine");
2023-01-07 00:39:19 +01:00
Debug.Log(TriggerDoor.ableToOpen);
if (TriggerDoor.ableToOpen)
{
StartCoroutine(WaitForAnimationAndMoveToScene(0.3f, collision));
2023-01-07 00:39:19 +01:00
}
}
}
2023-01-07 00:39:19 +01:00
}