
9장 강의 자료를 보면 시간을 기록하는데 있어서 Update()와 gameManager()의 시간 차가 생겨서 기록에 약간의 오차가 생긴다고 하는데
저는 아무리 해도 시간 차가 나지 않습니다 이런 경우는 어떤 경우인가요?
현제 저의 gameManger.cs 코드 입니다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class gameManager : MonoBehaviour
{
public static gameManager I;
void Awake()
{
I = this;
}
public GameObject square;
public GameObject endPanel;
public Text timeText;
public Text thisScoreText;
float alive = 0f;
// Start is called before the first frame update
void Start()
{
InvokeRepeating("makeSquare", 0.0f, 0.5f);
}
void makeSquare()
{
Instantiate(square);
}
// Update is called once per frame
void Update()
{
alive += Time.deltaTime;
timeText.text = alive.ToString("N2");
}
public void gameOver()
{
Time.timeScale = 0f;
endPanel.SetActive(true);
thisScoreText.text = alive.ToString("N2");
}
}
혹시 모르니 square.cs 코드도 올리겠습니다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class square : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
float x = Random.Range(-3f, 3f);
float y = Random.Range(3f, 5f);
transform.position = new Vector3(x, y, 0);
float size = Random.Range(0.5f, 1.5f);
transform.localScale = new Vector3(size, size, 0);
}
void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.tag == "balloon")
{
gameManager.I.gameOver();
}
}
// Update is called once per frame
void Update()
{
}
}
