简体   繁体   中英

Which would be the best design pattern in Unity for this problem?

I have a black object that supplies power to purple ones. Purples can't connect with each other without the power coming from the black one. Also there is a range parameter decides whether connect or not. I'm just learning about design patterns and I want to know which one would be better in this situation. Can you suggest me a pattern to use? I'm using line renderer for the connections by the way.

Picture below is just a representation of the game, the actual game will be 3d.

这可能有助于理解这个想法

The actual game looks like this. Dark purple one is the power supplier and the pink ones are conductors that are rotating around the yellow object and can be put on the grid cells one by one. 在此处输入图像描述

You aren't looking for a design pattern. You are looking for an Algorithm. Below is one I use for pathfinding in Unity. You'll have to adapt it a bit to suite your specific code.

https://github.com/Cornelis-Personal/AStar_CSharp

It is called the A* (A Star) Algorithm and it is very common with these sorts of problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM