Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

is it possible to attach canvas to a player(lets say)

Discussion in 'UGUI & TextMesh Pro' started by Uranium, Oct 5, 2014.

  1. Uranium

    Uranium

    Joined:
    Mar 17, 2013
    Posts:
    52
    so basicly i have setup an inventory system using the new ui system, and i would like to attach it to the player for better access and since its networked its better. is there anyway to actually setup the inventory that using the new ui as a child of the player?
     
  2. secondbreakfast

    secondbreakfast

    Joined:
    Jan 5, 2013
    Posts:
    98
    Yes, a world canvas
     
  3. Uranium

    Uranium

    Joined:
    Mar 17, 2013
    Posts:
    52
    when i am using the world canvas the canvas becomes huge, really huge... without an option to resize.
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    The canvas shouldn't be a child. Just make it world space where the event camera is set to the appropriate camera.

    --Eric
     
  5. JAKJ

    JAKJ

    Joined:
    Aug 17, 2014
    Posts:
    185
    What? You can directly set the worldspace canvas to any size you like. There's nothing wrong with it being a child. If you find working with tiny fractions too confusing, make the canvas 1000x1000 or whatever and then scale it by 0.001. It works fine. I just tested it again for myself, image as child of canvas as child of 3d object.
     
  6. Uranium

    Uranium

    Joined:
    Mar 17, 2013
    Posts:
    52
    but world space makes it move sideways, i am making an inventory. its not what i want...

    maybe its related to the fact that i am on beta 17?
     
  7. JAKJ

    JAKJ

    Joined:
    Aug 17, 2014
    Posts:
    185
    When you said you wanted to attach it to the player, it sounded like you wanted it to move with the player, as in be an object attached to the player. If you're just talking about making it easy to access through code, then no, that's silly, don't make it a child: Just put a public or serialized field in your code that takes a reference to a game object and drag the inventory into it.
     
    secondbreakfast likes this.
  8. Uranium

    Uranium

    Joined:
    Mar 17, 2013
    Posts:
    52
    alright, then another question, ive fixed all that. but is there a built-in way to stop rotation for the canvas? (the mouse look bugs it out)

    edit:
    nvm just instantiated it as a new one, the last question is that the ui is basicly rendered before the gun which makes it "hide" the gun. how can i stop that?
     
    Last edited: Oct 7, 2014
  9. Uranium

    Uranium

    Joined:
    Mar 17, 2013
    Posts:
    52
    all the answers for the problems that are at the message above are not needed anymore, i got a new one, it will be the latest hopefully:
    1. i am now using the world space and the thing about the world space, is that it doesnt really fit the inventory, i mean when u move around and go into a rock its just going through it and its basicly weird. is there a way to make it work as the overlay/camera or w/e but making it as a child (i guess u understand what i mean).

    Fixed! well that was a total waste of time. just switched it to Screen Space - Camera played around with it and now its fine.
     
    Last edited: Oct 7, 2014
  10. secondbreakfast

    secondbreakfast

    Joined:
    Jan 5, 2013
    Posts:
    98
    Your original question seemed like you wanted a canvas "attached" to your player. As in moving with the player and sized near the player and rotated with the player so that's why we answered your questions that way. Maybe you should have watched the beta UI videos. It would have cleared it up right away. Overlay and/or screen space canvases are used for canvases that ignore 3d world space.