帮我看看源代码的逻辑对不对,如何修改
源代码如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class gfdg : MonoBehaviour {
public float timer = 12;
// public bool OnTimer = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.H))
{
StartCoroutine(Countdown());
}
if(Input.GetKeyDown(KeyCode.J))
{
StopCoroutine(Countdown());
}
}
IEnumerator Countdown()
{
while (true)
{
timer -= Time.deltaTime;
yield return new WaitForSeconds(timer=12f);
Debug.Log("This message appears after 12 seconds!");
}
}
}