Interactive Media

Mohamed Al-Kaf - Media Explorations

Create Level One Scene

Written by: Mohamed Al-Kaf | Posted on: | Category:

Adding static cars to the scene. Screenshot 2019-05-01 at 10.25.03 pm.png

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;
        }
    }