I want the GameObject to show up when the variable Timer.TimeStart equals (for example 10), but it doesnt work. Have I made any mistakes? What can be false? Please help. Here is my code. The variable Timer.Time comes from anoher code, i leave it here too
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class timer : MonoBehaviour
{
public float TimeStart;
public TMP_Text textBox;
// Start is called before the first frame update
void Start()
{
textBox.text = TimeStart.ToString("F2");
}
// Update is called once per frame
void Update()
{
TimeStart += Time.deltaTime;
textBox.text = TimeStart.ToString("F2");
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class AKALI : MonoBehaviour
{
public bool canBePressed;
public KeyCode keyToPress;
[SerializeField]private timer Timer;
void Start()
{
gameObject.SetActive(false);
}
void Update()
{
if (Timer.TimeStart == 10)
{
gameObject.SetActive(true);
}
if (Input.GetKeyDown(keyToPress))
{
if(canBePressed)
{
gameObject.SetActive(false);
}
}
}
}