在过去的一天里,我一直在尝试将我的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;
}
}发布于 2018-05-14 04:58:26
通过在更改.hovering属性/变量的代码中突出显示和取消突出显示修复了该问题
if(Physics.Raycast(ray, out hit))
{
if (hit.collider.name.Contains("Hex"))
{
hovering=hit.collider.gameObject;
foreach(KeyValuePair<GameObject,Hex> h in HexData){
if (h.Key==hovering){
highlightNeighbors(true,h.Value);
h.Value.hovering=true;
}
else if(h.Key!=hovering && h.Value.hovering==true){
highlightNeighbors(false,h.Value);
h.Value.hovering=false;
}
}
}
}
else{
if (hovering){
hovering=null;
}
}https://stackoverflow.com/questions/50320252
复制相似问题