Find a colour in a Texture2D

I am trying to find a colour that is found on a texture but the method that i have used takes too much time.

string ColourString = colour.ToString ();
		for (int i = 0; i < ColourTex2D.height; i++)
			for (int j = 0; j < ColourTex2D.width; j++)
				Color TempColour = ColourTex2D.GetPixel(j, i);
				if (TempColour.ToString() == ColourString)
					CrosshairPos = new Vector2(((float)j/ColourTex2D.width) * ColourSelectSize.x, ColourSelectSize.y - ((float)i/ColourTex2D.height) * ColourSelectSize.y);

Is there a more effient way of achieving this?

I’m not sure what you are trying to do with this code. The is likely a better approach than what you are doing to accomplish what you want. But to answer your specific question, you can use Texture2D.GetPixels32() or Textur2D.GetPixels() in start to get the color of all the pixel data. Then you can directly access the pixel data without a GetPixel() call for each position in the texture. GetPixels32() and GetPixels() return a 1D array of the 2D pixel data.

Here is a script that uses GetPixels32(). Attached to a object with texture, clicking on that object will output the color at the cursor position.

using UnityEngine;
using System.Collections;

public class GetColor : MonoBehaviour {

	public Texture2D tex;
	private Color32[] pixels;
	private float width, height; 

	void Start () {
		Texture2D tex = (Texture2D)renderer.material.mainTexture;
		pixels = tex.GetPixels32();
		width = tex.width;
		height = tex.height;
	void Update () {
		RaycastHit hit ;
		var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		if (Input.GetMouseButton(0) && collider.Raycast(ray, out hit, Mathf.Infinity)) {
			Vector3 coord = hit.textureCoord;
			int w  = (int)(coord.x * width);
			int h  = (int)(coord.y * height);
			Debug.Log (pixels[h * (int)width + w]);

Note that your use of strings for comparisons is also of concern for performance in your code.