Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | ghoulfool |
I’m trying to change a texture on a key press. The cube has texture 1 (blue) normally whilst the down key is pressed the cube uses texture 2 (red). Once the key is released the cube goes back to the first texture is is blue once again.
I’m halfway there
extends Spatial
onready var cubey = get_node("/root/world/cube")
onready var mat1 = preload("res://icon.png")
onready var mat2 = preload("res://icon_inv.png")
func _input(event):
if event.is_action_pressed("down"):
cubey.set_surface_material(0, mat2)
# else:
# cubey.set_surface_material(0, mat1) # not working
Two things. I’m swapping the material, not the texture. And secondly the cube should revert to the first texture after the key is up.