title: Get world position of a pixel from texture2d/sprite
body: <p>I'm setting up an automatic system to be able to attach a sprite and it will gather all its colours and the world position of each sprite. A list/class of all the colours used has been set up but how would get the position of all these sprites? </p>
  
  <p>I have already tried doing this mathematically like getting the complete size of the sprite and then working out the size of each pixel and then working out the position from that. But this seems flawed due to the position of the sprite possibly changing.  </p>
  
  <pre><code>Sprite ColouredSpriteTexture = ColoredSprite.GetComponent&lt;SpriteRenderer&gt;().sprite;
          Texture2D ColouredTexture = ColouredSpriteTexture.texture;
          float XsizeF = ColoredSprite.transform.localScale.x;
          int Xsize = (int)XsizeF;
          float YsizeF = ColoredSprite.transform.localScale.y;
          int Ysize = (int)YsizeF;
          List&lt;Color&gt; TempList = new List&lt;Color&gt;();
  
      //Could spawn pixels by getting x and y size and dividing them by 100 50/100 = 0.50f
      //if the tile has a color then spawn pixel if not 0.50 += 0.50
      //TODO test if this logic will work
  
      float PixelSize = XsizeF / 100;
      float currentPos = PixelSize;
  
      for (int x = 0; x &lt; Xsize; x++)
      {
          for (int y = 0; y &lt; Ysize; y++)
          {
              int listAmount = TempList.Count;
              Color ColoredTex = ColouredTexture.GetPixel(x, y);
              float TextureAlpha = ColoredTex.a;
  
              if (!TempList.Contains(ColoredTex) &amp;&amp; TextureAlpha != 0)
              {
                  TempList.Add(ColoredTex);
                  ColorByNumber tempColor = new ColorByNumber();
                  tempColor.Color = ColoredTex;
                  tempColor.ColorNumber = listAmount;
                  ColorOptions.Add(tempColor);
  
              }
  
              if(TextureAlpha == 1)
              {
                  GameObject ColorPixel = Instantiate(PixelPrefab);
                  ColorPixel.transform.localScale = new Vector3(XsizeF, YsizeF, 0);
                  ColorPixel.transform.SetParent(this.transform);
                  ColorPixel.name = "Pixel (" + x.ToString() + "," + y.ToString() + ")";
              }
  
          }
      }
  </code></pre>
  
  <p>All I would need is somehow each pixel returning its position so I can store this data and be able to spawn anything on top of this pixel.</p>