minijam-166/scripts/planter.gd
2024-08-31 18:18:34 +02:00

19 lines
492 B
GDScript

class_name Planter
extends Node
@export var plants: Array[PlantType]
@onready var plant_scene = preload("res://objects/Plant.tscn")
@onready var timer: Timer = $Timer
func _unhandled_input(event: InputEvent) -> void:
if Input.is_action_just_pressed("plant") and timer.is_stopped():
var chosen_type: PlantType = plants[randi_range(0, plants.size() - 1)]
var plant = plant_scene.instantiate()
add_child(plant)
plant.init(chosen_type)
plant.plant(event.position)
timer.start()