find object of with specific conditions
I'm trying to create a card based game and for UI purposes I have specific slots but I need the script to be able to tell which cards are available and for that I need it to only search for ones that meet a certain condition this is my script:
private void Awake()
{
}
private void OnTriggerEnter(Collider other)
{
Instantiate(card, transform.parent = cardspace.transform);
Destroy(gameObject);
print("one more card collected");
}
private void Update()
{
cardspace = FindObjectOfType<CardSpace>(cardspace.available == true);
}
When I add the (cardspace.available == true) to my find object it is unable to detect any of them, is there a workaround, or am I doing something wrong
Answer by Synkrophosatron · Oct 13, 2020 at 04:48 PM
@Oreboat In the update() function, try using this: private void Update() { if (cardspace.available == true) { cardspace = FindObjectOfType(); Debug.Log("Card found of type" + gameObject.GetType()); // Or cardspaceVariableName.type if variable it's a name. } }
In other words, your problem is, to search for the ones with some conditions, so try searching first for the conditions then putting them to use. And one thing more is to check the output by using Debug.Log(). If you are searching for the card, you can print the result to console as required.