• 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 tourdetour · Jan 22, 2017 at 09:49 PM · uiguicanvasdrawingminimap

Draw minimap on panel

Hello, I have a panel in my UI canvas. I'd like to draw multiple coloured square on that panel (to make a simple minimap). I tried to draw a texture in the function OnGui at the position of the panel, but it doesn't work, the position doesn't match. I read there are differences between an old GUI system and the new UI system, I'm using unity 5.5 but I have no clue what the difference is between both.

Is there a way to draw coloured squares and lines on a panel in a canvas ?

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

2 Replies

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

Answer by tourdetour · Jan 29, 2017 at 07:38 PM

I found a way to draw on canvas using only the UI System reading Unity's tutorials.

It's actually pretty easy :

-Place a panel in your scene named "Minimap" and access it in a script using

GameObject minimap = GameObject.Find ("Minimap");

-Instantiate new panels and set the minimap as the parent

GameObject panel = Instantiate (Panel); panel.transform.SetParent (minimap.transform, false);

-Modify the panel's size to draw a square or a line, modify it's colour. You can also modify its position using its rect transform.

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

Answer by FlyingHighUp · Jan 23, 2017 at 02:22 AM

The GUI methods were the UI approach pre-Unity ~4.6. It's a real pain to work with past simple user interfaces, and doesn't make animation, layout, 3D interfaces, very easy. The new UI system integrates these systems a lot better, and I would recommend you focus on it (despite the harder learning curve) because it's going to make your life way better. I mean like, I t$$anonymous$$nk I shed a tear when it first came out. https://unity3d.com/learn/tutorials/topics/user-interface-ui

Here's an approach to creating a mipmap using the new UI system:

In t$$anonymous$$s screenshot, I have a 3d object on a custom layer I called "UIModelRender". I set a camera to only render t$$anonymous$$ngs on the UIModelRender layer. I then created a render texture and set it as the target texture of the camera, and then put the same texture in a RawImage UI Panel.

For your minimap, you would set t$$anonymous$$ngs up in a similar way. You could would your camera far above the play area and instantiate your squares and lines where the players actually are. Making sure those squares and lines are on a custom layer your players won't see.

The plus side is t$$anonymous$$s is easier to extend; e.g. if you wanted to add 3D objects or new symbols without touc$$anonymous$$ng too much code. However, it's a more performance intensive vs. an optimized 2D minimap. But to be honest, I would go with t$$anonymous$$s regardless. (T$$anonymous$$s also isn't just me, there are several tutorials out on youtube with t$$anonymous$$s same approach.)

alt text


tut.png (275.2 kB)
Comment
Add comment · Show 1 · 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 tourdetour · Jan 24, 2017 at 03:00 PM 0
Share

@FlyingHighUp Thank you very much, that would work !

However, I have already too much objects in my scene (10^4 cubes acting as walls for a maze), and it's already laggy, so adding twice as much as objects for the mini-map, that would be too much for older computers I think.

My maze is stored in a two dimensional array so it would be easy to draw a 2D mini-map. I'm more used to the openGL kind of rendering, and I still don't really know how to draw something using the new UI system, appart from using objects.

Thanks for you link, I'm going to read "Creating a Tic-Tac-Toe game using only the UI", they seem to draw lines and stuff using the UI, I could use that maybe.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

4.6 UI Canvas is smaller than normal 1 Answer

How do I keep an ui element in side of the canvas when scaling? 1 Answer

Problem with build version 1 Answer

uGUI Mask Content 0 Answers

Can the UI system effectively manage dozens of frequently update sprites? 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