Hey, I am trying to make a timer that stops when a enemy hits the player.
The problem is that the timer only stops if one specific enemy hits the player.
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Timer : MonoBehaviour
{
public bool stopTimer = false;
public float timeStart;
public Text textBox;
void Start()
{
textBox.text = timeStart.ToString("F2");
}
void Update()
{
if (stopTimer != true)
{
timeStart += Time.deltaTime;
textBox.text = timeStart.ToString("F2");
}else {
textBox.text = timeStart.ToString("F2");
}
}
void OnCollisionEnter2D(Collision2D col){
if (col.gameObject.tag == "Player")
{
stopTimer = true;
}
}
}