23 lines
725 B
GDScript
23 lines
725 B
GDScript
class_name TreeGenerator
|
|
extends Generator
|
|
|
|
@export var tree_materials: Array[Material]
|
|
@export var leaf_materials: Array[Material]
|
|
|
|
func _ready():
|
|
super._ready()
|
|
|
|
func generate(x: int, z: int) -> Node3D:
|
|
var instance := super.generate(x, z)
|
|
randomize_materials(instance)
|
|
return instance
|
|
|
|
func randomize_materials(instance: Node):
|
|
var tree := instance.find_child("tree") as MeshInstance3D
|
|
var tree_material := tree_materials[randi_range(0, tree_materials.size()-1)]
|
|
tree.set_surface_override_material(0, tree_material)
|
|
|
|
var leaves := instance.find_child("leaves") as MeshInstance3D
|
|
var leaf_material := leaf_materials[randi_range(0, leaf_materials.size()-1)]
|
|
leaves.set_surface_override_material(0, leaf_material)
|