Yes, I thought about it, but I ran into another problem.
My script is used on different nodes, respectively, they have different names.
I tried like this
TextureRect tmpTex = GetNode((String)Name) as TextureRect;
if ((inputEvent as InputEventMouseButton).Pressed == true) tmpTex.Texture = tex2;
and like this
if ((inputEvent as InputEventMouseButton).Pressed == false) (GetNode((String)Name) as TextureRect).Texture = tex1;
It causes runtime errors:
E 0:00:23:0802 Godot.NativeInterop.NativeFuncs.generated.cs:332 @ void Godot.NativeInterop.NativeFuncs.godotsharpmethodbindptrcall(IntPtr , IntPtr , System.Void** , System.Void* ): Node not found: "TextureRect3" (relative to "/root/Node3D/TextureRect3").
<C++ Error> Method/function failed. Returning: nullptr
<C++ Source> scene/main/node.cpp:1365 @ getnode()
Godot.NativeInterop.NativeFuncs.generated.cs:332 @ void Godot.NativeInterop.NativeFuncs.godotsharpmethodbindptrcall(IntPtr , IntPtr , System.Void** , System.Void* )
NativeCalls.cs:5886 @ Godot.GodotObject Godot.NativeCalls.godoticall1658(IntPtr , IntPtr , Godot.NativeInterop.godotnodepath )
Node.cs:685 @ Godot.Node Godot.Node.GetNode(Godot.NodePath )
SlotHandler.cs:56 @ void SlotHandler.GuiInput(Godot.InputEvent )
SlotHandlerScriptMethods.generated.cs:29 @ Boolean SlotHandler.InvokeGodotClassMethod(Godot.NativeInterop.godotstringname& , Godot.NativeInterop.NativeVariantPtrArgs , Godot.NativeInterop.godotvariant& )
CSharpInstanceBridge.cs:24 @ Godot.NativeInterop.godotbool Godot.Bridge.CSharpInstanceBridge.Call(IntPtr , Godot.NativeInterop.godotstringname* , Godot.NativeInterop.godotvariant** , Int32 , Godot.NativeInterop.godotvariantcallerror* , Godot.NativeInterop.godotvariant* )
E 0:00:23:0809 SlotHandler.cs:57 @ void SlotHandler.GuiInput(Godot.InputEvent ): System.NullReferenceException: Object reference not set to an instance of an object.
<C# Error> System.NullReferenceException
<C# Source> SlotHandler.cs:57 @ void SlotHandler.GuiInput(Godot.InputEvent )
SlotHandler.cs:57 @ void SlotHandler.GuiInput(Godot.InputEvent )
SlotHandlerScriptMethods.generated.cs:29 @ Boolean SlotHandler.InvokeGodotClassMethod(Godot.NativeInterop.godotstringname& , Godot.NativeInterop.NativeVariantPtrArgs , Godot.NativeInterop.godotvariant& )
CSharpInstanceBridge.cs:24 @ Godot.NativeInterop.godotbool Godot.Bridge.CSharpInstanceBridge.Call(IntPtr , Godot.NativeInterop.godotstringname* , Godot.NativeInterop.godotvariant** , Int32 , Godot.NativeInterop.godotvariantcallerror* , Godot.NativeInterop.godotvariant* )