Hello, I’m having an issue with the collider not triggering the “lose screen”. The game is designed in such a way that if an enemy crosses over the collider at the left end of the screen and the player’s health reaches zero, the “lose screen” will trigger. I have verified my code in the Github repository but I still have no trigger and no console error or anything. I rewatched the video but I’ve done everything I’m supposed to. I’ll paste my code anyway, just in case.
‘’’
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Level : MonoBehaviour
{
[SerializeField] int timeToWait = 4;
int currentSceneIndex;
void Start()
{
currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
if (currentSceneIndex == 0)
{
StartCoroutine(WaitForTime());
}
}
IEnumerator WaitForTime()
{
yield return new WaitForSeconds(timeToWait);
LoadNextScene();
}
public void LoadNextScene()
{
SceneManager.LoadScene(currentSceneIndex + 1);
}
public void LoadYouLose()
{
SceneManager.LoadScene("Lose Screen");
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DamageCollider : MonoBehaviour
{
private void OnTriggerEnter2D()
{
FindObjectOfType().TakeLife();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Lives : MonoBehaviour
{
[SerializeField] int lives = 5;
[SerializeField] int damage = 1;
Text livesText;
void Start()
{
livesText = GetComponent<Text>();
UpdateDisplay();
}
private void UpdateDisplay()
{
livesText.text = lives.ToString();
}
public void TakeLife()
{
lives -= damage;
UpdateDisplay();
if (lives <= 0)
{
FindObjectOfType<Level>().LoadYouLose();
}
}
}