[04] キャラクターがオブジェクトを拾う

オブジェクトに対する細かな設定が分からないので、今回はGDScriptで作ってます。
Area2DにSprite2D、Collision、Labelを設定
Labelは [E] として非表示。キー設定でEを追加

extends Area2D

var interactionLabel = false

func _ready() -> void:
	pass # Replace with function body.


func _process(delta: float) -> void:
	$Label.visible = interactionLabel
	
	if interactionLabel and Input.is_action_just_pressed("interaction"):
		queue_free()

func _on_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player"):
		interactionLabel = true

func _on_body_exited(body: Node2D) -> void:
	if body.is_in_group("Player"):
		interactionLabel = false

「interaction」のEキーが押されたらオブジェクトを消去
Area2DにPlayerグループが触れたらLabelを表示し、離れたら非表示

ゲームシーンにオブジェクトを配置して実行
PlayerのCollisionとオブジェクトのCollisionが触れるとLabelが表示される。Eを押すと拾われ消える

コメントを残す 0

Your email address will not be published. Required fields are marked *