Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Create gameobject in certain Canvas

Discussion in '2D' started by nikolas888, Sep 30, 2020.

  1. nikolas888

    nikolas888

    Joined:
    Dec 21, 2019
    Posts:
    5
    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
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    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...
     
  3. nikolas888

    nikolas888

    Joined:
    Dec 21, 2019
    Posts:
    5
    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?
     
  4. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    nikolas888 likes this.
  5. nikolas888

    nikolas888

    Joined:
    Dec 21, 2019
    Posts:
    5