Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Selecting certain hex prefabs in my hex grid.

Discussion in 'Scripting' started by Iphychoo, Feb 2, 2017.

  1. Iphychoo

    Iphychoo

    Joined:
    Sep 26, 2012
    Posts:
    12
    Hi guys.

    I have a question regarding hex grids. I have created a hex grid using Instantiate in unity C Sharp.
    Now that I have my grid, i'm trying to get lets say 20 hex's in the center of my spawned grid and only allow the played to build on those hexs.

    I'm still at a beginner - somewhat way to advance level of coding and using unity. Could you please help me and point me in the right direction?

    Picture attached is an example of what I want to do. Red hexs are the ones i want to allow the played to only use while others do other things.

    (Code wise I'm simply using gameobject instantiate with offsets :) )
    I though of setting each prefab a new name depending on it's location and manually finding the location of hexs i want for the player to do things with which then i can add them into an array and go from there?

    Thank you guys
     

    Attached Files:

  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    you might be interested in: https://forum.unity3d.com/threads/open-source-procedural-hexagon-terrain.233296/

    specific to your question, how are you storing the cells? or are you just instantiating them into the scene?

    if you're not storing the cells, you either store them in a collection somehow so you can calculate "1 up left, 1 up right, 1 left, 1 right" etc. or you could have a reference in each cell that points to each of those links (might be worth looking into for a navigation thing too...)
     
    StarManta likes this.
  3. Iphychoo

    Iphychoo

    Joined:
    Sep 26, 2012
    Posts:
    12
    I'm not actually storing my grid anywhere :(
     
  4. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889