Search Unity

Right way to show grid?

Discussion in 'General Graphics' started by ian0198, May 18, 2019.

  1. ian0198

    ian0198

    Joined:
    May 4, 2019
    Posts:
    2
    I want to show a square on top of the floor so the player can place some objects in my game. I was wondering about the performance of instanciating a tile using the player's mouse position. Is a game object the best way to show this UI stuff? Or does unity have another resource that can better tackle this problem?
    I've got the right result: https://giphy.com/gifs/elP4UNAIXpSJ7QyyWd/links

    The used code: https://gist.github.com/IanPedroV/b7952998da7e06fb86ea0831af1bc863

    Sorry if this is in the wrong place in the forums or something.
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,778
    Use plane with repeated texture of cross/square.
    Or write shader, to generate grid.
    Or use asset store, to find existing solutions.
     
    xVergilx likes this.
  3. Sh-Shahrabi

    Sh-Shahrabi

    Joined:
    Sep 28, 2018
    Posts:
    56
    Your link just opens giphy for me. So I am not sure what it is that you want. However if you want a grid repeating itself, the best way would probably be sampling a tiled texture. The using shader method which @AntySK mentioned, is fun and gives you easy control over line thickness and such. But the main issue is aliasing as the camera moves and also along steep angle of the plane. The repeated texture method he mentioned is the best way since you can use mipmaps and anisotropic filtering.

    The issue with that method is that you are losing control over line thickness. Another method is to use the using shader to generate grid method, but sampling a gradient map to determine the edges of the grid line. Like this you still have easy control over the thickness, but also dont have aliasing issue as your gradient map is receiving mip maps and anisotropic filtering
     
    Antypodish likes this.
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    This is the right place, though I think you confused people by talking about grids, and posting a link to a page of links to your gif rather than to the gif itself.


    What you're doing is fine, as long as you're not instantiating a new tile highlight for every grid position. Instantiate one, then keep it around and move it & hide/unhide it as needed. If your world is a nice flat plan, this really is probably the best way to go about it. The alternative would be to use a projector, which will let it conform to non-flat surfaces, but will be more expensive.
     
  5. ian0198

    ian0198

    Joined:
    May 4, 2019
    Posts:
    2
    I wish the forum had sent e-mails letting me know of the replies, thanks guys, sorry about the gif confusion.
     
  6. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    It does have. You just need to enable it in thread tools. (Or upon thread creation);
    Or, just use "Watch Thread" button.
     
    Antypodish likes this.