Exemplo n.º 1
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0) && Time.time > 2)
     {
         Vector2      rayPos = new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y);
         RaycastHit2D hit    = Physics2D.Raycast(rayPos, Vector2.zero, 0f);
         if (hit && !checking)
         {
             if (carta1 == null)
             {
                 carta1 = hit.transform.gameObject;
                 StartCoroutine(ShowCard1());
             }
             else
             {
                 carta2 = hit.transform.gameObject;
                 if (carta1 != carta2)
                 {
                     checking   = true;
                     infoCarta1 = carta1.GetComponent <CartaScript>();
                     infoCarta2 = carta2.GetComponent <CartaScript>();
                     StartCoroutine(Check());
                 }
                 else
                 {
                     carta1 = null;
                     carta2 = null;
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
    public void comprobarCartasIguales()
    {
        GameObject carta1 = cartasSeleccionadas[0];
        GameObject carta2 = cartasSeleccionadas[1];

        CartaScript carta1s = carta1.GetComponent <CartaScript>();
        CartaScript carta2s = carta2.GetComponent <CartaScript>();

        if (carta1s.IDCarta == carta2s.IDCarta)
        {
            soundManagerMemoria.Instance.playSoundAcierto();
            carta1s.setAcertada(true);
            carta2s.setAcertada(true);

            cartasRestantes.Remove(carta1);
            cartasRestantes.Remove(carta2);

            checkGameOver();

            for (int i = 0; i < cartasTotales.Count; i++)
            {
                cartasTotales[i].GetComponent <CartaScript>().comprobando = false;
            }
        }
        else
        {
            soundManagerMemoria.Instance.playSoundFallo();
            for (int i = 0; i < cartasTotales.Count; i++)
            {
                cartasTotales[i].GetComponent <CartaScript>().comprobando = false;
            }

            carta1s.darVuelta();
            carta2s.darVuelta();
        }

        cartasSeleccionadas.Clear();
    }