Hello, I’m having trouble with a simple 2d card game i’m making.
I have gameobjects to represent cards (all cloned from first one) and 5 gameobjects to represent fields on which the cards can be placed if they are unoccupied.
Here is the code
void OnMouseUp()
{
for (int i = 0; i < 5; i++)
{
GameObject currentCardField = GameObject.Find("CardField" + i.ToString());
Debug.Log (currentCardField.GetInstanceID());
CardFieldAttributes currentFieldAttributes = currentCardField.GetComponent("CardFieldAttributes") as CardFieldAttributes;
if (gameObject.renderer.bounds.Intersects(currentCardField.renderer.bounds) && !currentFieldAttributes.fieldTaken)
{
gameObject.transform.position = currentCardField.transform.position;
currentFieldAttributes.fieldTaken = true;
break;
}
else
{
gameObject.transform.position = pocetno;
}
}
Screen.showCursor = true;
}
Now the problem is it works as intended but only for CardField0, others just won’t work and i have no idea what the problem might be. It’s most probably something silly but I’m just baffled here…
as i said all fields and cards are clones so all settings apart from their names are the same.
What is the gameObject this script is attached to? Is it possible that the gameObject's bounds are always intersecting CardField0?
– hamstar@Baalhug sorry i forgot to mention it pocetno is my variable that holds initial card location so it returns to its start position if it's not dropped on field or that field is occupied.
– Corrosius