I have a question… how can you add for(int) values to each other.
I was trying to search in google but couldn’t find anything, so I imagine it like this
int OtherValue;
public void NeighborPixels(Vector2 pos)
{
for (int i = -CheckZone; i <= CheckZone; i++)
{
for (int j = -CheckZone; j <= CheckZone; j++)
{
OtherValue += Some.Value + OtherValue;
}
}
}
My goal is to be able to add for ints toghether.
My updated code is this …
public void NeighborPixels(Vector2 pos)
{
for (int i = -CheckZone; i <= CheckZone; i++)
{
for (int j = -CheckZone; j <= CheckZone; 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;
Debug.Log(ChosenPixelValue); // this gives output of one 1 and zeros which is right however I want them to be combined like total value of those pixels would be 1 because 1 + 0+0+0... is 1
}
}
}
}
generateScript.GetPixel is this…
public Pixel GetPixel(Vector2Int pos)
{
if(square.TryGetValue(pos, out Pixel pixel))
return pixel;
return null;
// square is dictionary which I use to find a pixel at specific position
}
Again my goal is to get the i and j values added to themselves 9 times.
Still not entirly clear what you want.
something like
totalValue += ChosenPixelValue.r + ChosenPixelValue.g + ChosenPixelValue.b + ChosenPixelValue.a;
if your pixel type is a color then this will be a FLOAT value sum
if pixel is a vector, then use x y z w instead of rgba, still a float sum
if pixel is a custom type that you created, with integer components, you use your own accessors
Also, if your GetPixel method returns a Pixel, why are then then using GetComponent on the result?
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;
}
}
}
}
}
And asked how you can add i and j to “total value”.
Why would changing line 10 to TotalValue = ChosenPixelValue + i + j; not solve your issue?
We’re trying really hard here to figure out what you want, but nobody knows what you’re actually trying to accomplish here. What is the value of ChosenPixelValue and what do you want TotalValue to equal?