En soit le problème est basique je souhaite faire arrêter un timer lorsque le joueur à dégommer tout les ennemis du niveau. J'aimerais afficher ce timer en tant que score sur le panneau de fin.
Code : Tout sélectionner
using System.Collections;
using UnityEngine.UI;
using UnityEngine;
public class Timer : MonoBehaviour
{
public Text counterText;
public int seconds, minutes;
void Start()
{
counterText = GetComponent<Text>() as Text;
}
// Update is called once per frame
void Update()
{
minutes = (int)(Time.time/60f);
seconds = (int)(Time.time%60f);
counterText.text = minutes.ToString("00")+":"+seconds.ToString("00");
}
}
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameOver : MonoBehaviour
{
public int nbEnemy = 0;
private Text txtEnemy;
private GameObject [] EnemyTab;
public Timer Timer;
public int Figsec, Figmin;
void Start()
{
txtEnemy = GameObject.Find("txtEnemy").GetComponent<Text>();
// compte ennemis
EnemyTab = GameObject.FindGameObjectsWithTag("Enemy");
foreach ( GameObject Enn in EnemyTab )
{
nbEnemy +=1;
}
txtEnemy.text="Enemy : "+ nbEnemy;
}
void Update()
{
nbEnemy = 0;
EnemyTab = GameObject.FindGameObjectsWithTag("Enemy");
foreach ( GameObject Enn in EnemyTab )
{
nbEnemy +=1;
}
txtEnemy.text="Enemy : "+ nbEnemy;
if(nbEnemy == 0)
{
Figsec = Timer.seconds;
Figmin = Timer.minutes;
Debug.Log("Perfect !"+ Figmin);
}
}
}