Werkzeuge des Player - SamToorchi/Godot-Zombi-Game GitHub Wiki
sword.gd
extends Node2D
var TYPE = null
const DAMAGE = 1
var maxamount = 1
func _ready():
TYPE = get_parent().TYPE
$anim.connect("animation_finished", self, "destroy")
$anim.play(str("swing", get_parent().spritedir))
func destroy(animation):
queue_free()
sword.gd
func use_item(item):
var newitem = item.instance()
newitem.add_to_group(str(newitem.get_name(), self))
add_child(newitem)
if get_tree().get_nodes_in_group(str(newitem.get_name(), self)).size() > newitem.maxamount:
newitem.queue_free()
player.gd
func _physics_process(delta):
if Input.is_action_just_pressed("a"):
use_item(preload("res://scene/sword.tscn"))