Create Level One Scene
Adding static cars to the scene.
Ending level using Collider and trigger in unity. I placed an empty game object at the end location of the car path. so when the three objects intersect and a button is pressed it would change the scene.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MoveScene2 : MonoBehaviour
{
private bool ViewAtEnd;
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.name == "Circle")
{
ViewAtEnd = true;
Debug.Log("ViewerReady");
}
}
private void Update()
{
if (ViewAtEnd && Input.GetKeyDown(KeyCode.Space))
{
Debug.Log("change");
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
}
private void OnTriggerExit2D(Collider2D other)
{
ViewAtEnd = false;
}
}