Hello , I am new to unity & C# .
I am working on a 2D game that is time based per level.
I do not seem to have any obvious errors in visual studio.
A)The starting time updates as it should
B)Debug .Log shows that the trigger is activated.
Problem is the time does not count down after the player moves through my trigger , please help
What needs to happen is :
The Game starts , the time is shown but does not start yet.
When the Player goes through a trigger (Starting Door for example) , after that the time counts down.
When the player reaches the exit the timer needs to stop (I have not yet started with the coding for the exit).
Here is what I have so far:
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
using UnityEngine.Experimental.PlayerLoop;
using UnityEngine.UI;
public class StartTimer : MonoBehaviour
{
float currentTime = 0f;
float startingTime = 120f;
public Text countdownText;
void Start()
{
currentTime = startingTime;
countdownText.text = currentTime.ToString(“0”);
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.name == “player”)
{
Debug.Log(“Start Timer”);
Update();
}
void Update()
{
currentTime -= 1 * Time.deltaTime;
countdownText.text = currentTime.ToString(“0”);
if (currentTime <= 0)
{
currentTime = 0;
}
}
}
}
I hope this makes sense , thank you in advance