xyz OK. I did the following for getting it to work with my full class:
- As you said, the declaration was outside. It has to be inside
- I deleted the file with csproj extension and the old solution if existed
- I used the menu for creating the solution again
- And after that, it didn't work, and it seems it was because I had a typo in the name of my variable. The program told me it doesn't existed, because it didn't!
- After that, I tried my original code to change the TextureRect texture with a button, and it didn't work neither. I have no idea why, but I just deleted it, added a TextureRect again, and now everything works.
As now I know that my custom C# code works, I will be able to make my game. Thanks a lot, you are fantastic!
For me it was confusing that the editor didn't warn me that the variable name was spelled wrong. Usually that gives a red line in Visual Studio below the word so you know in the moment that it wasn't. I suppose that in some place or using Visual Studio or Visual Studio Code as editors it may warn me, right?
The other thing is that I don't knwo why the TextureRect stopped working, or maybe it was not visible by some reason.