public void NeighborPixels(Vector2 pos)
{
for (int i = -3 / 2; i <= 3 /2; i++)
{
for (int j = -2 / 2; j <= 2 /2; j++)
{
if (generateScript.GetPixel(new Vector2Int(Mathf.RoundToInt(pos.x) + i, Mathf.RoundToInt(pos.y) + j)) != null)
{
var ChosenPixelValue = generateScript.GetPixel(new Vector2Int(Mathf.RoundToInt(pos.x) + i, Mathf.RoundToInt(pos.y) + j)).GetComponent<Pixel>().Value;
TotalValue += ChosenPixelValue;
if (TotalValue < 1)
{
generateScript.GetPixel(new Vector2Int(Mathf.RoundToInt(pos.x) + i, Mathf.RoundToInt(pos.y) + j)).GetComponent<SpriteRenderer>().color = Color.red;
}
}
}
}
}

my basic question is how can I add i and j values to total value that the output equals for example 9.

in my code I want to add i and j every time they change so I can get the total value, if in 9 pixels there are two pixels that have value of 1 both and seven of pixels that have value of 0, I want to add them together so I get 2 in total.

Why are you using division? -2 /2 and 2 / 2 simply equal -1 and 1. And an integer datatype cannot be 1.5 (3/2). And please don’t multipost, you’ve already asked this question, out of respect for the people that have helped you here https://discussions.unity.com/t/876369