Hi! So, in my game, I have a feature where I want the player to be able to click on any metal object in the world and have it react (change shader).
Currently, I have a node called 'MetalComp' that I plan to use as a component that i'll attach to scenes that represent metal objects. I figured this would be appropriate since i'm essentially attaching behavior to a node that gives it the 'property' of being metal.
Here's the script attached, metal_comp.gd
class_name MetalObjectComp extends Node
@export var hint: HighlightHint
@export var sprite: Sprite2D
signal metal_body_clicked
func toggle_selected():
var mat = sprite.get_material()
if mat.get_shader_parameter("onoff") == 0:
mat.set_shader_parameter("onoff", 1)
else:
mat.set_shader_parameter("onoff", 0)
func toggle_hint():
if sprite.get_material().get_shader_parameter("Alpha") == 0:
hint.enable_hint()
else:
hint.disable_hint()
I also have a node attached to the player, Painter, that acts as the controller for these 'click' events. My question is, how can I effectively link the Painter to the nodes with the MetalComp component?
If the root node of the target was MetalComp, I could just do if node is MetalComp, but since it's a child of the target node, I'm struggling to think of a clean way to do this.