added working vending machine
This commit is contained in:
37
scripts/vendingmahcine.gd
Normal file
37
scripts/vendingmahcine.gd
Normal file
@@ -0,0 +1,37 @@
|
||||
extends Node3D
|
||||
|
||||
@export var item : Resource
|
||||
@export var item_name : String
|
||||
@export var item_price : int
|
||||
@onready var anim_player = $AnimationPlayer
|
||||
@onready var vend_ray = $VendRay
|
||||
@onready var label_3d = $Label3D
|
||||
|
||||
var active = true
|
||||
var level_control
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
level_control = self.get_node("../")
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
pass
|
||||
|
||||
func interact():
|
||||
if active == true:
|
||||
if level_control.money >= item_price:
|
||||
level_control.money -= item_price
|
||||
anim_player.play("vend")
|
||||
#label_3d.text = str(lerp(item_price,0,delta))
|
||||
else:
|
||||
pass #add "too poor" text here
|
||||
|
||||
func vend():
|
||||
var item_vend = item.instantiate()
|
||||
item_vend.position = vend_ray.global_position
|
||||
item_vend.transform.basis = vend_ray.global_transform.basis
|
||||
item_vend.linear_velocity += vend_ray.global_transform.basis * Vector3(0,0,10)
|
||||
active = false
|
||||
get_parent().add_child(item_vend)
|
||||
Reference in New Issue
Block a user