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

Placing your character preview in the inventory?

Discussion in 'Scripting' started by TrinxudasDoZe, Sep 12, 2016.

  1. TrinxudasDoZe

    TrinxudasDoZe

    Joined:
    Sep 10, 2016
    Posts:
    41
    Hi guys,
    So i am using inventory pro and created an inventory for my game. But i want also to add the character preview to the left side of it. I have no idea where to start, could someone tell me if there is something in inventory pro that allows ous to do that, or what code i need to use?

    cumpz,
    Vasco
     
  2. TrinxudasDoZe

    TrinxudasDoZe

    Joined:
    Sep 10, 2016
    Posts:
    41
  3. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
    You could have a new camera "InventoryPreview", which is a child of the player, and has a culling mask set to only render the layers which the comprises the player (Player layer + weapons layer, etc.), and positioned so that the player is displayed in the correct position on screen. That camera's depth will be set higher than your main camera so that it renders on top like UI does. Toggle that camera on and off when the inventory opens and closes.

    Alternatively, create a new object that will represent the player in the inventory.
     
  4. Vedrit

    Vedrit

    Joined:
    Feb 8, 2013
    Posts:
    514
    Or have the camera render to a render texture that you attach in your inventory UI.
     
    LiterallyJeff likes this.
  5. TrinxudasDoZe

    TrinxudasDoZe

    Joined:
    Sep 10, 2016
    Posts:
    41
    Hum i am sorry i'm not so good.
    I have set the culling mask to Nothing, because i dont see any option that only shows the player character. The option that is closer to that is the "Default" wich shows normal objects (terrain,grass etc.) How can i set it so it only views the player?
     
  6. Vedrit

    Vedrit

    Joined:
    Feb 8, 2013
    Posts:
    514
    Create a new layer only with the character and other things you want in the character view, and assign those objects to the layer
     
  7. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
    Yes each GameObject has a Layer defined at the top of the Inspector panel underneath the name. If you click the Layer drop down, there will be an "Add Layer" option, where you can add a "Character" layer. Assign your player objects to that layer, then assign your new camera to only render the Character layer.
     
  8. TrinxudasDoZe

    TrinxudasDoZe

    Joined:
    Sep 10, 2016
    Posts:
    41
    But how can i show the camera in a portion of the inventory? I have done that and now camera preview only shows the character. But i still dont know how to place the camera in the inventory :S
     
  9. Vedrit

    Vedrit

    Joined:
    Feb 8, 2013
    Posts:
    514
    I find the simplest solution is to create a render texture that you can put in the UI and have your character camera render to it
     
  10. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
    To elaborate, every Camera has a "Target Texture" field which accepts a Render Texture. You can create a Render Texture just like any other asset by right clicking in your project files and going to Create -> RenderTexture.

    Once you've assigned your Render Texture to your new Camera, you can add a new UI -> Raw Image object, and give the Raw Image component your Render Texture. So now whatever the camera sees will be rendered to that texture, and displayed in your UI.
     
    Vedrit likes this.
  11. TrinxudasDoZe

    TrinxudasDoZe

    Joined:
    Sep 10, 2016
    Posts:
    41
    Thank you so much guys, and im sorry if i look so dumb i'm getting started :) but thanks for wasting your time with me :D
     
  12. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
    Not a problem. That is actually a fairly advanced technique, and if I didn't want to help people I wouldn't log into these forums ;)
     
  13. Vedrit

    Vedrit

    Joined:
    Feb 8, 2013
    Posts:
    514
    No problem! I had to do this when I was setting up a character view in the character info window.
    Another thing I would suggest is to put a 'platform under your character that only shows in the character camera and has no colliders. Something to give players a reference point
     
  14. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,620
    In the demo scene of Inventory Pro there is a character window that shows the character. Is that what you want? If so, the prefab for that is in the project and you can also make sure the "ToTextureCamera" object (a camera) which is found under the Third Person Controller is copy/pasted to your own character. When this other camera is positioned correctly (pointed at your character), it will render your character for the Character Window in Inventory Pro (provided you have linked the render output file to the Character Image object in the Character Window.)

    If that's not exactly what you want, I imagine you can tweak it a little till you do get what you want. All the parts are there.
     
  15. TrinxudasDoZe

    TrinxudasDoZe

    Joined:
    Sep 10, 2016
    Posts:
    41
    Thanks but i already managed to get what i want :). But still apreciate it