I have a project where I flip a card after 5 seconds, then I want to start a countdown timer of x seconds. After x seconds the card flips again.
I found a good example for the timer here, but that works inside a Update() method. My problem comes from the fact that the rotation of the card is made also inside the Update() method.
If I put the timer inside the Update() method, as soon as the Update() method is called the timer starts, and I don't want it to start it as soon as I call the Update() method, but when I want to start ip, wich is 60 seconds after I flip the card.
If I put the timer inside a method other than Update() then the timer start but never decrease.
using UnityEngine;
using System.Collections;
public class Juego1Carta2 : MonoBehaviour
{
public float velocidadDeRotacion = 100.0f;
public Sprite cartaBase;
public Sprite cartaDelantera;
private bool carta2Activada = false;
private bool cartaDeLado = false;
float tiempoDeJuego = 2;
IEnumerator Esperar()
{
yield return new WaitForSeconds(5);
transform.position = new Vector3(Screen.width / 2, Screen.height / 2 +GetComponent<SpriteRenderer>().bounds.size.y, 0);
carta2Activada = true;
Regresa();
}
void Regresa()
{
Update();
}
// Use this for initialization
void Start ()
{
StartCoroutine (Esperar());
}
// Update is called once per frame
void Update ()
{
if (carta2Activada)
{
transform.Rotate(Vector3.up * Time.deltaTime * velocidadDeRotacion);
if (transform.eulerAngles.y >= 90)
{
SpriteRenderer Carta = GetComponent<SpriteRenderer>();
if (Carta.sprite == cartaBase)
{
Carta.sprite = cartaDelantera;
cartaDeLado = true;
carta2Activada = false;
}
else
{
Carta.sprite = cartaBase;
cartaDeLado = true;
carta2Activada = false;
}
tiempoDeJuego = 60;
}
}
tiempoDeJuego -= Time.deltaTime;
if (tiempoDeJuego <= 0)
{
print("Fin del tiempo");
}
if (cartaDeLado)
{
transform.Rotate(Vector3.up * Time.deltaTime * velocidadDeRotacion);
if (transform.eulerAngles.y >= 180)
{
transform.eulerAngles = new Vector3(0, 0, 0);
cartaDeLado = false;
carta2Activada = false;
return;
}
}
}
}
Is there a way to rotate the card and make a countdown timer at the same time?
I'm sorry, maybe this is a very obvious question but after 3 consecutive days working on this, I'm more than burnout...