space_shooter/Assets/Scripts/GameManager.cs
2025-02-28 22:42:44 +05:30

45 lines
1.0 KiB
C#

using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public GameObject prefab;
public float Limit = 7;
public float SpawnInterval = 2;
float timer;
public GameObject gameOverUI;
public Text textscore;
public void AddScore()
{
textscore.text = (int.Parse(textscore.text)+1).ToString();
}
public void Restart()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
public void GameOver()
{
gameOverUI.SetActive(true);
}
// Update is called once per frame
void Update()
{
if(timer < SpawnInterval )
{
timer += Time.deltaTime;
}else
{
timer =0;
Instantiate (prefab,new Vector3 (Random.Range(-Limit,Limit), transform.position.y),Quaternion.identity);
}
}
}