Выполнение кода 1 раз в полсекунды
как я могу сделать так, чтобы мой счет увеличивался не так быстро, а каждые полсекунды -1 секунда?
вот мой код:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Control : MonoBehaviour
{
public Text scoreText;
public int score;
public float time;
private float timeStart;
public float Second = 1f;
void Update()
{
time -= Time.deltaTime;
if (time <= 0)
{
ScoreManager.score += 1;
time = timeStart;
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ScoreManager : MonoBehaviour
{
[SerializeField] Text HighscoreText;
[SerializeField] Text scoreText;
public static float score;
int highscore;
void Start()
{
score = 0;
}
void Update()
{
highscore = (int)score;
scoreText.text = "" + highscore.ToString();
if (PlayerPrefs.GetInt("score") <= highscore)
{
PlayerPrefs.SetInt("score", highscore);
}
HighscoreText.text = "" + PlayerPrefs.GetInt("score").ToString();
}
}
Источник: Stack Overflow на русском