Add script for dissolve dagger

This commit is contained in:
VAILLANT Jeremy
2021-05-12 13:51:34 +02:00
parent 710647b655
commit eac8d2b408
4 changed files with 75 additions and 8 deletions
+41 -6
View File
@@ -1,9 +1,38 @@
extends Spatial
const time_max = 3000 # msec
onready var meshes = {
"dagger": {
"mesh": $"Main Scene Props/dagger",
"value": 0.0,
"label": "Dagger",
"lock": false,
"tick_reference": null
}
}
func _ready():
$Dialog/ConfirmEscape.set_title("Quit ?")
$Dialog/ConfirmEscape.set_text("Voulez vous vraiment quitté ?")
func _process(_delta):
# Event key "escape" and "godot event" ui_end
if Input.is_action_just_pressed("ui_end"):
_confirm_before_quit()
# Event dissolve in object searched by gamer
for mesh in meshes:
if meshes[mesh]["lock"] == true and meshes[mesh]["mesh"] != null:
if meshes[mesh]["tick_reference"] == null:
meshes[mesh]["tick_reference"] = OS.get_ticks_msec()
if OS.get_ticks_msec() < meshes[mesh]["tick_reference"] + time_max:
meshes[mesh]["value"] += 0.01
meshes[mesh]["mesh"].get_surface_material(0).set("shader_param/dissolve_amount", meshes[mesh]["value"])
else:
meshes[mesh]["mesh"].call_deferred("free")
meshes[mesh]["mesh"] = null
func _notification(what):
# Notification for android back action
@@ -11,13 +40,19 @@ func _notification(what):
_confirm_before_quit()
func _confirm_before_quit():
var confirm = ConfirmationDialog.new()
confirm.set_title("Quit ?")
confirm.set_text("Voulez vous vraiment quitté ?")
add_child(confirm)
confirm.connect("confirmed", self, "_quit_to_menu")
confirm.popup()
$Dialog/ConfirmEscape.popup()
# Back to main scene
func _quit_to_menu():
Global.goto_scene("res://scenes/main.tscn")
# Event when user click/touch dagger
func _on_dagger_input_event(camera, event, click_position, click_normal, shape_idx):
_initialize_mesh_ref("dagger", event)
func _initialize_mesh_ref(meshInstance, event):
if meshes[meshInstance]["lock"] == false and (event is InputEventMouseButton or event is InputEventScreenTouch):
meshes[meshInstance]["lock"] = true
func _on_ConfirmEscape_confirmed():
_quit_to_menu()