如何更改未选中对象的透明度?

时间:2016-07-03 06:53:55

标签: unity3d

我有一个补丁三种风格的游戏。我想更改不匹配所选颜色的所有节点的透明度。所以想象一下你选择紫色,一切都不是紫色,我想暗淡。

$(document).ready(function() {
window.onload = $('#username').html(localStorage.getItem("storageName"));

weeklyMenu();
function weeklyMenu() {

    var menu = ["meatloaf", "albondigas", "enchiladas", "lasgna", "chicken, mash potatoes, mac & cheese", "turkey burgers, sweet potatoes fries", "stuffed peppers", "french soup"];

    var randomMenu = menu[Math.floor(Math.random() * menu.length)];
    var splitMenu = randomMenu.split();
    $('.words').text(splitMenu[0]);
}

$("button").on("click", function() {

    weeklyMenu();

});
}); 

以上是我用来做出选择的内容。 protected void matchByLinkedList() { List<Node> nodes = new List<Node>(); //makes a new list of nodes when touched Debug.Log(List<Node>); LinkedListNode<Node> linkedListNode = linkedList.First; //creates a list of the selected nodes. int element = linkedListNode.Value.element; //This gets the value of the selected Node's element } 是我在预制件上放置的字段,用于识别颜色。红色= 1,紫色= 2等。

我是否需要执行不等于元素(1)编辑变换的element?在我的思考过程中,我觉得我错过了一些介于两者之间的步骤。

我真的不明白我是如何灵活地列出所有不匹配的项目,然后对这些项目进行转换。

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

有很多方法可以做到这一点,通常最好尽可能避免循环。您可以通过在Node类中添加静态Node字段并将任何节点的InstanceId与其进行比较来实现此目的。

public class Node : MonoBehaviour{

internal static Node SelectedNode;

//call this somehow
public void OnSelect(){
  SelectedNode = this;
}

void Update(){
  if(this.GetInstanceID() == SelectedNode.GetInstanceID())
  {
    //dim this
  }
}
}

修改

确保您不要将GameObject的InstanceId与Component的InstanceId进行比较。两个对象必须具有相同的类型,否则它总是返回false。

相关问题