- Home /
Timer - CS0029: Cannot implicitly convert type `float' to `bool'
I'm getting this error when trying to setup my timer (Assets/Scripts/ShroomScript.cs(47,25): error CS0029: Cannot implicitly convert type float' to
bool')
using UnityEngine;
using System.Collections;
public class ShroomScript : MonoBehaviour {
private heroController player;
public float timeLeft = 60f;
// Use this for initialization
void Start () {
player = GameObject.FindGameObjectWithTag("Player").GetComponent<heroController>();
}
void OnTriggerEnter2D(Collider2D col) {
if(col.CompareTag("Player")){
AudioSource AS = col.GetComponent<AudioSource>();
AS.PlayOneShot(AS.clip);
Destroy(gameObject);
if (player.curHealth <=4)
{
player.HealthIncrease(1);
} else if (player.curHealth >= 5)
{
player.HealthIncrease(0);
}
player.shroomPower = true;
// timeLeft = 5;
}
}
void Update () {
if(timeLeft > 0)
{
Debug.Log("Waiting"+timeLeft);
timeLeft -= Time.deltaTime;
if (timeLeft = 0)
{player.shroomPower = false;}
}
}
}
Comment
Best Answer
Answer by Suddoha · Nov 11, 2016 at 11:14 PM
You've written the assignment operator '=' instead of the equality operator '==' in line 47.
It should be
if(timeLeft == 0)
However, please be aware that the timeLeft variable will most-likely not exactly hit the value 0.0f.
Maybe you'd rather wanna try
if(timeLeft <= 0)
Your answer
![](https://koobas.hobune.stream/wayback/20220612100516im_/https://answers.unity.com/themes/thub/images/avi.jpg)