Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Nov 13, 2012 at 04:40 PM by KiraSensei for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by KiraSensei · Nov 13, 2012 at 09:52 AM · cameragui

Display a gameObject like a GUITexture

Hello everyone !

I'm having a hard time with a life bar in a multiplayer FPS game. I created a gameobject like that (so a gameobject with a mesh filter and a mesh renderer). Every character has two cameras : one for the general display of the level and other players, and another one for the GUI display (remaining ammo for example). I want to display my life bar with the second camera.

My problem is that even if I gave the same layer to my life bar as my GUIText gameobjects for ammo, the life bar is drawn, but can go threw walls (like it is not drawn in last, contrary to all other "GUI" gameobjects.

My "GUI" camera already has a depth superior to the main camera, and if I remove the mesh filter and mesh renderer from my life bar and replace them by a GUIText, it works fine ...

This problem is driving me crazy :( Thanks by advance !

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Montraydavis · Nov 13, 2012 at 01:01 PM 0
Share

Do you mean using a 3D object as if it were a GUI texture? You could just make the the gameObject a child of the Camera component, position it correctly, and it should always follow the camera at the set position .

avatar image PAEvenson · Nov 13, 2012 at 01:04 PM 0
Share

Did you specify the Culling $$anonymous$$ask for each Camera?

avatar image KiraSensei · Nov 13, 2012 at 01:09 PM 0
Share

@$$anonymous$$ontraydavis : yes, as if it were a GUITexture. It is already a child of my camera, but my problem is that it goes threw walls if my character is against a wall.

@PAEvenson : yes, I can see as I want my game objects. The main camera has every culling masks BUT one specific ton my "GUI" things, and the other camera has only the specific mask.

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by Wolfram · Nov 13, 2012 at 01:34 PM

Your problem is that a regular GameObject has no knowledge about that it's supposed to be a "GUI" object. You will need to create and assign a shader to it that ignores any existing z-Buffer values. As a result, the object will always be rendered, independent from its actual depth, and independent form other scene objects.

Unless you already have a suitable shader, download the builtin shaders from http://unity3d.com/support/resources/assets/built-in-shaders , find the "Unlit-Normal.shader" if your bar does not use alpha/transparency, or "Unlit-Alpha.shader" if it does. Copy it into your project, edit it, give it a new name (for example, adding "(GUI)" to its name), and add this line directly before the Pass section:

 ZTest Always

EDIT: with this approach, you don't need a separate camera to render your GUI GameObjects, you can just place them as children to your regular camera, and adjust their local coordinates accordingly. On the other hand, for your two-camera-approach, a special shader shouldn't be required. Make sure your GUI camera has a higher "depth" setting, and the "clear flags" are set to "Depth only".

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image KiraSensei · Nov 13, 2012 at 01:59 PM 0
Share

Actually I am already using a cutout vertex-lit shader on it to handle an effect. Can we combine shaders ?

avatar image Wolfram · Nov 13, 2012 at 02:01 PM 0
Share

Same approach, make a copy of the shader, give it a different name, and add the line above. In your case, the filename of the builtin shader is AlphaTest-VertexLit.shader

avatar image Montraydavis · Nov 13, 2012 at 02:03 PM 0
Share

Strumpy Shade Editor can achieve this too. : http://forum.unity3d.com/threads/56180-Strumpy-Shader-Editor-4.0a-$$anonymous$$assive-Improvements

avatar image Wolfram · Nov 13, 2012 at 02:05 PM 0
Share

@$$anonymous$$ontraydavis: that's a powerful tool, but a bit of an overkill for the problem at hand ;-)

avatar image Montraydavis · Nov 13, 2012 at 02:10 PM 0
Share

@Wolfram: True true . I was thinking he/she could learn from Strumpy though, and maybe just spiff out this specific part of strumpy, and figure it how strumpy does it lOl. But yes, it is a bit of overkill lOl.

Show more comments
avatar image
0

Answer by Montraydavis · Nov 13, 2012 at 01:14 PM

Ah in that case, it has to do with your camera being positioned either too far behind the player that it goes through objects, or improper colliders.

Perhaps, try using a Raycast that will detect if the cameras 'back' is x distance from the wall, and stop it from moving once it has reached this point.

http://docs.unity3d.com/Documentation/ScriptReference/RaycastHit.html

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image KiraSensei · Nov 13, 2012 at 01:18 PM 0
Share

$$anonymous$$y camera does not go threw walls. It is only my "life bar" game object that goes threw. Text meshes game objects that have the same culling mask are rightly displayed and don't go threw walls...

I was careful to put my camera inside my collision capsule :)

avatar image Montraydavis · Nov 13, 2012 at 01:23 PM 0
Share

Well, I'm thinking it's basically the same issue, except with the texture and not the camera.

The only way I can really think to solve this is by using Raycasts, as I mentioned before, but on the object that's going through walls, and have it raise above the character while he is on the wall, or either in front / side of him. The problem is definitely the positioned of the object interfering with the position of the player.

avatar image KiraSensei · Nov 13, 2012 at 01:27 PM 0
Share

Ok, so a simple possibility is to put the game object into the capsule collider, and reduce the scale to have what I want ?

avatar image Montraydavis · Nov 13, 2012 at 01:30 PM 0
Share

Exactly. You need the gameObject to be close enough so that it doesn't go into the wall when you're x distance away from it. But like I said, alternatively, you can just re-position it when you're against the wall. Either approach should work.

Try it out, and mark as answered if this helps! Thanks for using Unity3D .

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I set up a GUI around multiple cameras? 1 Answer

It is possible to have a Camera rect on TOP of a GUI 0 Answers

Disabled Camera acts strangely outside of editor (solved) 0 Answers

Camera in Interface 1 Answer

Webplayer bug after coming back from sleep mode 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges