• 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
Question by jpthek9 · Apr 28, 2015 at 02:25 AM · unity 5graphicsgridrtsprojector

Drawing an overlay grid?

I'm trying to draw an overlay grid that can move around. Is t$$anonymous$$s possible and if so, how can I do it? Thanks :).

Example:

alt text

Comment
Damjan-Mozetic
kluepfel
spacehelmetboy

People who like this

3 Show 0
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
Best Answer

Answer by Tomer-Barkan · Apr 28, 2015 at 04:53 AM

Of course it's possible.

There may be several ways to do it. If your game is a 2D game, you can either have one sprite for the entire grid, or several small sprites, one for each square, depending on whether or not your grid is constant in size.

If it's a 3D game, you can create a mesh shaped like the grid, and have a tiled texture on it. Again, t$$anonymous$$s is if the grid is fixed side, otherwise you can create many small meshes. You can use sprites in a 3D game too.

Last option that comes to mind, and the preferred one IMO, is using Unity's new Canvas component, in World Space render mode. T$$anonymous$$s allows to create somet$$anonymous$$ng like a billboard inside the game world, w$$anonymous$$ch could work great fro your grid. Inside the canvas you can have a tiled image, and also a mask to prevent the corners from rendering. Otherwise you could use a "Grid Layout Group" and arrange single tile images inside, where the corners will have their "Image" component disabled, w$$anonymous$$le the others will be enabled.

Comment
jpthek9
J.Mad
danielnetzer
Damjan-Mozetic
StarCmd
kluepfel
Mr_Miagton

People who like this

7 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 BroVodo · Apr 28, 2015 at 05:17 AM 0
Share

you can create many small meshes

Or you could have a single mesh, scale it, and change the number of times the material repeats the texture http://docs.unity3d.com/ScriptReference/Material.SetTextureScale.html
avatar image BroVodo · Apr 28, 2015 at 05:49 AM 0
Share

Although from the picture it seems OP may want a grid that isn't square... so your way is probably better

avatar image jpthek9 · Apr 28, 2015 at 06:16 AM 1
Share

The canvas idea is brilliant! It works perfectly for my game since it brings the grid down to 1 draw call and is easily customizable.

avatar image J.Mad · Jun 05, 2015 at 10:11 PM 1
Share

I have tried to make a grid of squares 300 x 300 (big map in a strategy game). I have tested that 3 ways. #1 World canvas with grid layout and many small panels as children - not possible, out of limit 65k elements. #2 Many small sprites - possible but needs lots of cpu and memory. #3 One big quad with tiled texture - low memory and cpu using.

avatar image

Answer by BroVodo · Apr 28, 2015 at 05:42 AM

 using UnityEngine;
 
 //using System.Collections;
 
 
 
 public class Grid : MonoBehaviour
 {
     
     [ SerializeField ] private Transform _transform;
     
     [ SerializeField ] private Material _material;
     
     [ SerializeField ] private Vector2 _gridSize;
     
     [ SerializeField ] private int _rows;
     
     [ SerializeField ] private int _columns;
     
     
     
     void Start()
     {
         
         UpdateGrid();
         
     }
     
     
     
     public void UpdateGrid()
     {
         
         _transform.localScale = new Vector3( _gridSize.x, _gridSize.y, 1.0f );
         
         _material.SetTextureScale( "_MainTex", new Vector2( _columns, _rows ) );
         
     }
     
 }


Here's a package with a prefab demo


gridpackage.zip (12.4 kB)
Comment
jpthek9
Alex_TNT
EthanBar
Mr_Miagton

People who like this

4 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 jpthek9 · Apr 28, 2015 at 06:18 AM 2
Share

Thanks for this answer. I've decided that I'm going to use a canvas for this task - since I can turn on and off grid tiles at my leisure - but this seems like another great solution that might help others (and it also might be faster).

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

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

Related Questions

Unity 5 specular realtime GI not working in build 2 Answers

Error Failed to initialize Unity Graphics 1 Answer

Problems making game grid for space rts. (just visible to player not highlighting grid cells) 1 Answer

Change grid scale or scale whole library 0 Answers

How to change editor grid size by script? 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