• 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 /
avatar image
0
Question by raptorkwok · Feb 18, 2014 at 09:09 AM · 3d model

Placing 3D elements in front of a GUI 2D menu background

I use the following codes to create a 2D menu ( script attached to Main Camera ):

 public class MyScene : MonoBehaviour {
     public Texture backgroundTexture;
     void OnGUI() {
         // display bg texture
         GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), 
                         backgroundTexture, ScaleMode.StretchToFill);
     }
 }

I have a 3D model that has to be placed in front of this background image. I tried to place the 3D model in front of the Main Camera, but once the background image is loaded, the 3D model disappears / hide behind the background image.

What should I change ?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by POLYGAMe · Feb 18, 2014 at 09:41 AM

I'm pretty sure the GUI system is designed to always be on top. You could assign your BG image to a quad instead, or you could possibly use two cameras, one to render the GUI stuff, and another camera on top of that to render the 3D stuff and ignore the GUI. You'll just have to play with camera depths and layers/culling.

Comment
Add comment · Show 3 · 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 raptorkwok · Feb 18, 2014 at 09:45 AM 0
Share

Any example of 2 cameras working together with camera depth & layers ? I try the 1st suggestion first ( assign to a quad ) , but what is the size of the quad ? There are different size of screens .

avatar image POLYGAMe · Feb 18, 2014 at 10:08 AM 0
Share

You could either design a texture with a black (or whatever colour you want) empty area, so that the texture sits in the middle and you just adjust the quad until it looks good across a variety of resolutions. It's not optimal but I'm guessing you're a beginner and the other option is to look into converting world cartesian coords into screen, so you can make the quad scale to screen size, as that code you wrote does for GUITextures. You could also just muck about and see what sizes work and set the scale at runtime, depending on screen width/height.

As for the two camera option. Simply create another camera, set it to the exact same position as the other and create layers. One for one camera, another for the other, then tell each camera what to cull in its options. You'll also need to set the camera depths so that the 3D model one renders on top and set it Its clear flags to Depth Only, so it doesn't block out the other camera with background colour. Fairly straightforward but a bit much to put in an answer here. Best check out the unity docs on cameras.

avatar image Linus · Feb 18, 2014 at 10:25 AM 2
Share

https://www.google.com/search?btnG=1&pws=0&q=unity3d+gui+behind+3d+object

First hit (might vary) seems good http://forum.unity3d.com/threads/119520-How-to-set-GUITexture-behind-of-3d-object

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

19 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

3d model setup? 0 Answers

Script: import a 3d model to the scene from an outside folder 2 Answers

Export from Blender to Unity - Colliders 1 Answer

How do I make and object move in sync with its animation? 1 Answer

FBX model missing polygons on import 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