I'm trying to create instances of Sprite3D and randomize their texture.
I randomize what texture will be set however all instances end up with the same texture. As if all instances share the same configuration, the final texture for every Sprite3D will be the one from the last set_texture() call.
extends Spatial
var textures = [load("res://images/image1.png"), load("images/image2.png")]
func _ready():
var objects = get_node("Objects")
var w = 10;
var h = 10;
for i in range(10):
var newSprite = Sprite3D.new()
newSprite.translate( Vector3( w*rand_range(-1, 1), 0, h*rand_range(-1, 1)) )
var r = randi() % 2
newSprite.set_texture(textures[r]);
objects.add_child(newSprite)
pass
How do I assign different texture by code?