Create gameobject in certain Canvas

Hi everyone,
I made to develop a piece of code where i try to put group of gameobject and show them into canvas.
The code is looks like this:

private void InitTalonCards()
{
float startPosition = 2.0f;
float multiplier = 1.15f;

foreach (var obj in _zingDealer.TalonCards)
{
GameObject gameObj = (GameObject)obj;
// Preparation to init is next
// Check later to scale svg. Probably we will have better sharpness.
gameObj.transform.localScale = new Vector3(0.3f, 0.3f);
gameObj.transform.localPosition = new Vector3 (startPosition * multiplier - 6.80f, 2.5f, -1.0f);

GameObject firstDeck = (GameObject)Instantiate(gameObj, new Vector3(0, 0, 0),Quaternion.identity);
firstDeck.transform.SetParent(canvacesOfFirstDeck.transform, false);
multiplier += 1.15f;

// Instantiate(firstDeck);

}
}

At this point on run i can see in palliate the object are created and have proper values but the problem is on GUI it is not showing.

When i comment the code where i trying to put gameobjects in canvas and just to show them using the method Instantiate…It is showing on GUI but all of gameobjects are created globally and they not in certain canvas.

Thanks,
Nikola

Hi @nikolas888

There is a separate UI forum for UI questions. Also, code is really hard to read without code tags, I personally won’t bother to read any code that isn’t formatted, although I can’t speak for others…

Hi @eses
Thank you for replay,i’m the new one here, so do you mean on UI Toolkit is right place to ask question?

@nikolas888

“do you mean on UI Toolkit is right place to ask question?”

If your question is about UI Toolkit then yes, but if your question is about UGUI, then there is this forum:

1 Like