Last active
April 22, 2018 23:36
-
-
Save DevEarley/ec17aa0d10ae0ee450d3f3af07496970 to your computer and use it in GitHub Desktop.
MessageManager for Godot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extends Node | |
| export var node_paths = [] | |
| var player_node = null | |
| var message_node = null | |
| var nodes = [] | |
| func _ready(): | |
| message_node = get_node("../Message") | |
| player_node = get_node("../Player") | |
| for node_path in node_paths: | |
| nodes.append(get_node(node_path)) | |
| func get_dist_from_player(a): | |
| return a.transform.origin.distance_to(player_node.transform.origin) | |
| func get_first_node_in_range(): | |
| for node in nodes: | |
| var dist = get_dist_from_player(node) | |
| if(dist<node.MinDistance): | |
| return node | |
| return null | |
| func _process(delta): | |
| var closest_node = get_first_node_in_range() | |
| if(closest_node != null): | |
| message_node.set_text(closest_node.Message) | |
| else: | |
| message_node.set_text("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment