admin管理员组

文章数量:1313275

When placing the objects, I output their z value to the console and they gradually decrease, as they're meant to - but in the game all the objects have the same 0 value (zero) which is causing errors with clicking on cards because it "randomly" decides which one you've clicked on (and is rarely the one at the front).

The cards all have a sorting order too which increases the closer it gets to the screen - I thought maybe it should decrease so I tried it the other way round and this was not the case.

This is what the z values should equal: Console output

I won't insert images of the Z value of all cards but here's just for the first where you can already see it is 0, not -0.03: Inspector You can also see in scene that the cards are clearly placing all on the same z-axis as they just show a thin line. Cards in Scene

The y values successfully decrease though so I'm not sure why it's fine for some and not for others.

Here is my code for dealing the card:

public void DealCards()
{
    for (int i = 0;i<7;i++)
    {
        float yOffset = 0;
        float zOffset = 0.03f;
        int sortingOrder = 1;
        foreach(string card in tableaus[i])
        {
            //yield return new WaitForSeconds(0.01f);
            GameObject newCard = Instantiate(cardPrefab, new Vector3(tableauPos[i].transform.position.x, tableauPos[i].transform.position.y - yOffset, tableauPos[i].transform.position.z - zOffset), Quaternion.identity, tableauPos[i].transform);
            print((tableauPos[i].transform.position.z - zOffset));
            newCard.name = card;
            newCard.GetComponent<Selectable>().row = i;
            newCard.GetComponent<Renderer>().sortingOrder = sortingOrder;
            if (card == tableaus[i][tableaus[i].Count-1])
            {
                newCard.GetComponent<Selectable>().faceUp = true;
            }

            sortingOrder++;
            yOffset += 0.5f;
            zOffset += 0.03f;
        }
    }
}

When I get rid of the transform at the end of the statement, the Z axis change but the card's are ginormous and not being parented to the tableaus causes problems in other parts of my code - if the Y axis works whether or not it's parented, why not Z?

And just for a clearer idea of my construction, here is an image of the game: Game image

本文标签: