Now About Social Code
summaryrefslogtreecommitdiff
path: root/scripts/player.gd
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/player.gd')
-rw-r--r--scripts/player.gd23
1 files changed, 22 insertions, 1 deletions
diff --git a/scripts/player.gd b/scripts/player.gd
index 275100a..3b1fb6a 100644
--- a/scripts/player.gd
+++ b/scripts/player.gd
@@ -20,6 +20,8 @@ var bullet_inst = preload("res://prefabs/bullet.tscn")
var ammo: int = 100
var fire_timer: float = fire_rate
+var interactable: Node3D = null
+
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
@@ -80,12 +82,31 @@ func fire_weapon(delta: float) -> void:
fire_timer = 0
else:
fire_timer += delta
-
+
+func do_interact() -> void:
+ if Input.is_action_just_pressed("interact") and interactable != null:
+ if interactable.has_method("get_contents"):
+ var contents = interactable.get_contents()
+ if contents > 0:
+ ammo += contents
+ print("Got ", contents, " ammo!")
+ else:
+ print("Empty container")
func _physics_process(delta: float) -> void:
do_grapple()
+ do_interact()
fire_weapon(delta)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
pass
+
+
+func _on_interactable_enter(body: Node3D) -> void:
+ interactable = body
+ print("Got interactable")
+
+func _on_interactable_exit(body: Node3D) -> void:
+ if interactable == body:
+ interactable = null