Hello i was writing a simple if statement in C#, and Unity gave me an error.
To be more specific the error was in the if statement:
if (timeLeft = 0){
timeLeft = 5;
}
But i do not now wath’s wrong.
Can someone please help me ? My script is below.
There is also a picture of the error below.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class CountDown : MonoBehaviour {
public Text timeText;
private float timeLeft = 5;
private int destroyerTimer;
void Awake ()
{
}
void Start ()
{
timeText.text = "";
}
void OnTriggerEnter (Collider other)
{
if (other.gameObject.CompareTag ("Pick Up2"))
{
destroyerTimer = destroyerTimer + 1;
StartCoroutine (processTask4 ());
}
}
void Update ()
{
if (destroyerTimer > 0)
{
timeLeft -= Time.deltaTime;
timeText.text = "time left:" + Mathf.Round (timeLeft);
if (timeLeft < 0)
{
timeText.text = "";
}
}
else
{
timeText.text = "";
}
if (timeLeft = 0)
{
timeLeft = 5;
}
}
IEnumerator processTask4()
{
yield return new WaitForSeconds (5);
destroyerTimer = destroyerTimer - 1;
}
}