【发布时间】:2018-10-23 12:28:13
【问题描述】:
过去一天,我一直在尝试将我的 love2D 游戏移植到 unity 中,但目前我遇到了一个主要问题:我无法复制邻居突出显示。
问题是: 如果我从一个六边形悬停到另一个六边形,如果我去过的六边形与前一个六边形共享邻居,则这些邻居将不会突出显示。
这是我突出显示邻居的代码:
foreach(Tile tile in hex.neighbours){
tile.GetComponent<Renderer>().material.color=tile.data.Elements[tile.data.Element];
if (on){ // are we highlighting?
print("Highlighting..");
if(tile.GetComponent<Renderer>().material.color==tile.data.Elements[tile.data.Element] ){
//if the color of the neighbors is the same as it's element's color(meaning it hasn't been highlighted yet), highlight it.
print("changing color!");
tile.GetComponent<Renderer>().material.color=tile.GetComponent<Renderer>().material.color+new Color32(20,20,20,0);
}
}
else{
//unhightlighting
if(tile.GetComponent<Renderer>().material.color!=tile.data.Elements[tile.data.Element]){
//if the color of the neighbors isn't the same as it's element's color(meaning it's highlighted), unhighlight it.
tile.GetComponent<Renderer>().material.color=tile.data.Elements[tile.data.Element];
}
}
}
这是我检查是否应该突出显示或取消突出显示的方式:
foreach(KeyValuePair<GameObject,Hex> h in HexData){
if (hovering==null && h.Value.hovering){
h.Value.hovering=false;
//if we're not hovering over anything and a hexagon still has it's neighbors highlighted, unhighlight it's neighbors
if (h.Value.neighborsHighlighted==true){
highlightNeighbors(false,h.Value);
h.Value.neighborsHighlighted=false;
}
}
if(!h.Value.hovering && h.Value.neighborsHighlighted){
{
//if a hexagon isn't being hovered over, but it's neighbors are still hightlighed, unhighlight them.
highlightNeighbors(false,h.Value);
h.Value.neighborsHighlighted=false;
};
}
if (h.Value.hovering && h.Value.neighborsHighlighted==false){
//if we're hovering over a hexagon and it's neighbors aren't highlighted, highlight them
highlightNeighbors(true,h.Value);
h.Value.neighborsHighlighted=true;
}
}
【问题讨论】:
标签: c# unity3d hexagonal-tiles