0

For my 2D Game; I have a panel with an image Component (with a sprite) and a GridLayout component. On the panel i have also put a script that creates buttons for the panel (as children)

public void InitializeGrid(int rows, int columns, List<RbzFilteredWord> words)
{
    RectTransform myRect = GetComponent<RectTransform>();
    buttonHeight = myRect.rect.height / (float)rows;
    buttonWidth = myRect.rect.width / (float)columns;
    GridLayoutGroup grid = this.GetComponent<GridLayoutGroup>();
    grid.cellSize = new Vector2(buttonWidth, buttonHeight);

...
    for (int i = 0; i < rows; i++)
    {
        for (int j = 0; j < columns; j++)
        {
            button = (Button)Instantiate(prefab);
            button.transform.SetParent(transform, false);
          ...
}

Problem:

The text of each button must indicate the color of the pixel (from the underlying image) at the pivot location of that button

I know that this method is available: GetPixel(x,y), but i don't know which coordinates i need to use as parameters for this method, since i'm a noob at unity

DennisVA
  • 2,068
  • 1
  • 25
  • 35

1 Answers1

0

x and y are the position indexes in the pixels bidimensional array of teh texture.

That is:

  • x goes from 0 to the width - 1 of the texture image (in pixels)
  • y goes from 0 to the height - 1 of the texture image (in pixels)
Glantucan
  • 138
  • 7