How to connect a set number of nodes on a map into a grid?
Hello!
I'm trying to learn using Unity and C#.
In my 2 player game the map is visually represented with a sprite on which in a pre-determined set of coordinates script spawns "Node" objects. I have successfully managed to implement node creation, drawing their graphics, stashing them neatly in the hierarchy and a few other things.
Each node knows its number, its coordinates, its Allegiance (player, opponent, none or contested basically), its Region and the amount of influence of each player.
Even though in the world they are spread apart coordinates-wise on various distances, I would like these nodes to be connected in a "grid", and influence "flows" along the "tubes" connecting the grid. Really it would probably suffice if my nodes knew which nodes are adjacent to them, but it would also be great if I could adjust the "thickness" of these tubes based on variables (distance to node, its region, blah blah...) of the "adjacent" nodes.
There are not very many nodes at the moment (~100), however it would be nice of course if I could include more nodes in the future without too too much trouble.
I could probably go about it the long and hard way (I have the map of nodes, so I can make list of connections for each node by number, for example, node 1 is adjacent to nodes 43, 7 and 14 etc., manually then import it into Unity using JSON ...), but I was wondering if more experienced community members have some advice for me?
That's a pretty complex list of needs. I can't really answer as the script would take quite a chunk of my time to put together however this is the approach I'd take...
Tag each Node (e.g. create a Node tag and make sure they're all tagged as Node).
Then look up findgameobjectswithtag.
You'll need to do a foreach loop on that list of objects and get the distance of each one.
Record however many you want as being close enough to have a linking line, Record the gameobject for each one you want to draw a line from and to and then use line renderer to draw the line.
That's the rest of your weekend gone :D
Sweet, thanks for your input! I think implementing this will take more than one weekend ;)
Actually I linked to the singular version of find game objects with tag.
[THIS][1] is the right link - and good luck
Your answer
Follow this Question
Related Questions
Help with dynamic loading or occlusion culling in scenes on 2D metroidvania? 1 Answer
A good 2D tile map editor that works with Unity? 1 Answer
[SOLVED] Converting a Generic List to JSON in Unity 3 Answers
Movement and zoom of camera on the map 0 Answers
How to create own 2d map with roads and moving cars. 0 Answers