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 /
avatar image
3
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 this possible and if so, how can I do it? Thanks :).

Example:

alt text

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
7
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, this 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. This allows to create something like a billboard inside the game world, which 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, while the others will be enabled.

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 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/$$anonymous$$aterial.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 $$anonymous$$any small sprites - possible but needs lots of cpu and memory. #3 One big quad with tiled texture - low memory and cpu using.

avatar image
4

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
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 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.

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

Best solution for Grid-based building system? 0 Answers

Keyword 'void' cannot be used in this context 1 Answer

Fog and Blur not affecting terrain and some trees! 1 Answer

Compact Wordle Graphics in Unity3D 0 Answers

Is it possible to set smoothness and metallic of a mesh per-vertex instead of the whole material? 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