error CS0103: The name `wing' does not exist in the current context

I’m using a code that is working fine to change the wing’s color of a butterfly, through texture’s offset value. Here is the code:

using UnityEngine;
using System.Collections;

public class ButterflyColor : MonoBehaviour { 	
	    	
	public void SetButterflyColorValue(string myButterflyVal)
	{
    			
		if (myButterflyVal == "blue") {
		renderer.material.mainTextureOffset = new Vector2(0, 0);
	  	}
 		else if  (myButterflyVal == "orange"){
			renderer.material.mainTextureOffset = new Vector2(0.25F, 0);
		}
		else if (myButterflyVal == "yellow"){
			renderer.material.mainTextureOffset = new Vector2(0.5F, 0);
		}
		else  {
			renderer.material.mainTextureOffset = new Vector2(0.75F, 0);
		}
	}		
}

But I need to change a bunch of wings, tagged with the tag “wings”. How can I do that? I am trying to do the following code but returns the error: CS0103: The name `wing’ does not exist in the current context

using UnityEngine;
using System.Collections;

public class ButterflyColor : MonoBehaviour {
	    	
	public void SetButterflyColorValue(string myButterflyVal)
	{
		
		wing = GameObject.FindGameObjectsWithTag("wings");
		
		if (myButterflyVal == "blue") {
		wing.renderer.material.mainTextureOffset = new Vector2(0, 0);
	  	}
 		else if  (myButterflyVal == "orange"){
		wing.renderer.material.mainTextureOffset = new Vector2(0.25F, 0);
		}
		else if (myButterflyVal == "yellow"){
		wing.renderer.material.mainTextureOffset = new Vector2(0.5F, 0);
		}
		else  {
		wing.renderer.material.mainTextureOffset = new Vector2(0.75F, 0);
		}
	}		
}

Thank you :wink:

The error you get from Unity will include two numbers inside round brackets. The first of these numbers tells you which line the error occured on. I assume you get line 9, which is where you use a variable called wing. Since this variable is used without being declared the compiler correctly complains. Wing is presumably a GameObject so you need:

GameObject wing = GameObject.FindGameObjectsWithTag("wings");

If you want to change all the wings in your current scene I would do something like this:

Gameobject[] allWings = GameObject.FindGameObjectsWithTag("wings");
foreach(GameObject wing in allWings)
{
//Wing change code
}

I would also probably change the series of if statements to a switch statement