I have 3 types of Buildings
. I want to create let's say 20 of them, at random, with their translate
also random. I'm trying this code, but I think it overrides each one witht the latest one:
extends Spatial
onready var scenaryPlaneDims = get_node("Floor").scale
var building1Instance = preload("res://Buildings/Building1.tscn").instance()
var building2Instance = preload("res://Buildings/Building2.tscn").instance()
var building3Instance = preload("res://Buildings/Building3.tscn").instance()
# Called when the node enters the scene tree for the first time.
func _ready():
randomize()
for n in 20:
call_deferred("add_building_to_root", building1Instance)
call_deferred("add_building_to_root", building2Instance)
call_deferred("add_building_to_root", building3Instance)
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func add_building_to_root(instance):
get_tree().get_root().add_child(instance)
instance.set_translation(Vector3(randi()%50,0,randi()%50))
#instance.set_scale(Vector3(100,100,100))
How can I create individual instances of those Buildings with specific attributes?