//GameObjectに
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class Score : MonoBehaviour
{
public GameObject objFinish;
public GameObject Player;
public Text txtScore;
public GameObject txtClear;
int iScore = 0;
int remaining;
[SerializeField] int timeLimit;
[SerializeField] Text timerText;
float time;
void Start()
{
txtScore.text = "Score:";
objFinish.SetActive(false);
txtClear.SetActive(false);
}
void Update()
{
time += Time.deltaTime;
//time変数をint型にし制限時間から引いた数をint型のlimit変数に代入
remaining = timeLimit - (int)time;
timerText.text = $"のこり:{remaining.ToString("D3")}";
if (remaining <= 0)
{
Player.gameObject.SetActive(false);
objFinish.SetActive(true);
Invoke("GameRestart", 3.5f);
}
}
public void SetScore()
{
iScore += 10;
txtScore.text = "Score:" + iScore.ToString();
if (iScore >= 300)
{
txtClear.SetActive(true);
Player.gameObject.SetActive(false);
Invoke("GameRestart", 3.5f);
}
}
public void GameOver()
{
objFinish.SetActive(true);
Invoke("GameRestart", 3.5f);
}
public void GameRestart()
{
Scene activeScene = SceneManager.GetActiveScene();
SceneManager.LoadScene(activeScene.name);
}
}
//____________________________
//Ballに
using UnityEngine;
using UnityEngine.SceneManagement;
public class Ball : MonoBehaviour
{
public float Value = 0.1f;
public float kaiten;
public GameObject explosionPrefab;
Score sManager;
SePlay sePlay;
private float step_time;
bool canDieSoon;
void Start()
{
sManager = GameObject.Find("ScoreManager").GetComponent();
explosionPrefab = GameObject.FindWithTag("Particle");
sePlay = GameObject.Find("SePlayer").GetComponent();
step_time = 0.0f;
canDieSoon = false;
}
void LoadEnding()
{
SceneManager.LoadScene("MainScene");
}
private void OnTriggerEnter2D(Collider2D col)
{
if (col.gameObject.CompareTag("bullet"))
{
Destroy(col.gameObject);//敵キャラを削除
Destroy(gameObject);//ミサイルを削除
sManager.SetScore();
sePlay.Play("SE2");
Instantiate(explosionPrefab, transform.position, Quaternion.identity);
}
else if (col.gameObject.CompareTag("Player"))
{
col.gameObject.SetActive(false);
sePlay.Play("SE0");
sManager.GameOver();
}
}
void Update()
{
transform.position += new Vector3(-Value, 0, 0);
kaiten += 0.2f * Time.deltaTime;
transform.Rotate(0, 0, kaiten);
}
}