I want to ask about how to make a bonus time in my game when player hit the time bonus item. Here is my code
CountDownTimer
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class countDownTimer : MonoBehaviour {
public bool lol;
public int timeLeft = 5;
public Text countdownText;
public GameObject menang, kalah, reset, kanan, kiri, atas, bola, pause;
// Use this for initialization
void Start()
{
StartCoroutine("LoseTime");
lol = false;
}
// Update is called once per frame
void Update()
{
countdownText.text = ("Time Left = " + timeLeft);
if (menang.active == true)
{
StopCoroutine("LoseTime");
countdownText.text = ("Score = " + timeLeft);
}
if (timeLeft <= 0)
{
StopCoroutine("LoseTime");
countdownText.text = ("Time Left = " + timeLeft);
kalah.SetActive(true);
reset.SetActive(true);
atas.SetActive(false);
kanan.SetActive(false);
kiri.SetActive(false);
bola.SetActive(false);
pause.SetActive(false);
}
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.transform.tag == "Player")
{
menang.SetActive(true);
//StopCoroutine("LoseTime");
}
}
IEnumerator LoseTime()
{
while (true)
{
yield return new WaitForSeconds(1);
timeLeft--;
}
}
}
Item
void OnTriggerEnter2D(Collider2D other)
{
if (other.transform.tag == "Player")
{
timeleft + 20;
}
}
and the problem is, when I add 20 time in my timeleft, the console says that Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement.
Thanks before