Hello everyone. I'm following this tutorial to make arrows to my game. However, when I try to fire the bow the game crashes and the following error keeps pops up:
"Invalid call. Nonexistent function 'Instance' in base 'Nil'."
The guy in the video is attaching his script to KinematicBody2D Player, but I want the bow my character uses to move with the mouse, so I'm assigning this script to the bow.
Any ideas on how to fix this? I am new to programming in general, so you'd help me a lot. Thanks in advance.
This is my code:
extends Node2D
onready var bow_end = $BowEnd
onready var bow_cooldown = $Bowcooldown
export (PackedScene) var arrow
func _process(_delta):
look_at(get_global_mouse_position())
func _unhandled_input(event: InputEvent) -> void:
if Input.is_action_just_pressed("ui_attack") and is_visible_in_tree():
shoot()
func shoot():
var arrow_instance = arrow.instance()
add_child(arrow_instance)
arrow_instance.global_position = bow_end.global.position
If any more information is needed, I'll be happy to provide.