One thing I noticed is that you’re using an int for some of your GUI elements. They need to be floats. That could be causing several issues.
If I understand correctly, you want to click one of the buttons to toggle its colour. Keep in mind that OnGUI() executes every frame. That means when you change btnT, it will change for all of your textures.
A better way to do it would be to have a two-dimensional array that tracks what colour each button is. Try something like this: (WARNING: untested code)
public bool [,] MapArray = new bool [];
for your map declaration. Then in your loop, do
public Texture RedTexture;
public Texture WhiteTexture;
for (int K = 0, K <= MapArray.GetUpperBound(0); K++) {
for (int L = 0; L <= MapArray.GetUpperBound(1); L++) {
if (GUI.Button(new Rect(WhateverYourRectVarIs, MapArray[K,L] ? RedTexture : WhiteTexture))) {
MapArray[K,L] = !MapArray[K,L];
}
}
}
Here, I’ve defined that a “false” value is a white button, and a “true” value is red. You could easily swap those, and it will probably work fine. I’m also using a shortcut construct that works like this:
? : ;
Not sure if this construct saves processor cycles, but it does tend to save keystrokes.
The advantage of using an array is that you can easily serialise it to save it to disk, and you can iterate through it easily like we’ve done here. I’ve always found that the best way to accomplish things like this is to always have an internal “authoritative” data structure, and just have your GUI parrot it off. It saves a lot of headaches. Also, having an array allows you to easily resize your map later if you want to. Make sure to set the array’s size in your inspector before running it.
y thank you this explains something,
I like using arrays, I tried to make it work, but it didn’t, I posted an thread before this called (How to “talk” to objects) it is failed title, I edited it after I made it in ARRAY TEXTURES, I have posted whole code that I made with array variables, so if you like check it out you can.
Btw that is the only way how I KNOW “how to use” arrays in this problem (by knowing I mean I know how to use it logically not just copy paste without understanding. That my code looks nice to me but I did something wrong because I don’t know conditions that C# needs for using arrays in GUI or for loops) I’ll try to figure out your code. I haven’t got it yet, but it looks nice and I think I’ll get it (compleately understand how it works) after some testing and playing with it.