I’m trying to do a simple flipping card game where i need to get the key of “1” to flip the number 1 card. However i got multiple number 1 prefab and i need them to flip in order.
using UnityEngine;
using System.Collections;
public class CardsController : MonoBehaviour {
public int prefabID;
public AudioSource audio;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
if(Input.GetKeyDown("1") && prefab = 1 )
{
audio = GetComponent<AudioSource>();
audio.Play ();
GetComponent<Animation>().Play("Flip_hideDuplicate");
StartCoroutine("Remove");
if(Input.GetKeyDown("1") && prefab = 2 )
{
audio = GetComponent<AudioSource>();
audio.Play ();
GetComponent<Animation>().Play("Flip_hideDuplicate");
StartCoroutine("Remove");
}
}
}
IEnumerator Remove()
{
yield return new WaitForSeconds (0.75f);
Destroy (gameObject);
}
}
It only works for the first getKey. I understand that maybe because its in update function, therefore its too fast for it to get the second getKey. But is there any other method to achieve what i want?
I am still new to Unity and thanks in advance.