using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LevelLoader : MonoBehaviour
{
void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == "Player");
{
StartCoroutine(LoadAsynchronously(1));
}
}
IEnumerator LoadAsynchronously (int sceneIndex)
{
AsyncOperation operation = SceneManager.LoadSceneAsync(1);
while (!operation.isDone)
{
yield return null;
}
}
}
I tried changing some things but it's not working anyways if someone can help me. is supposed to work when collides with that object but IDK why nothing happens
Try to make a bool flag for it
bool loadScene = false;
void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == "Player");
{
if(!loadScene){
StartCoroutine(LoadAsynchronously(1));
loadScene = true;
}
}
}