Tim Cooley
Tim Cooley

Reputation: 759

How to change transparency of objects not selected?

I have a patch three style game. I want to change the transparency of all the nodes that don't match a selected color. So imagine you select purple, everything not purple I want to dim.

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

}

Above is what I am using to make the selections. element is a field I have put on the prefab to identify the color. Red = 1, Purple = 2 etc..

Do I need to do a foreach that doesn't equal element (1) edit transform? I feel like I am missing some steps in between in my thought process.

I don't really understand how I am supple to make a list of all items that don't match and then set the transform on those.

Thanks for the help.

Upvotes: 0

Views: 32

Answers (1)

Bizhan
Bizhan

Reputation: 17085

There are many ways to do this, generally it's better to avoid loops as much as possible. you can achieve this by having a static Node field in your Node class and compare InstanceId of any node with it.

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
  }
}
}

edit

make sure you don't compare the InstanceId of a GameObject with InstanceId of a Component or so. both Objects must have the same type or otherwise it always returns false.

Upvotes: 1

Related Questions