20 lines
796 B
GDScript
20 lines
796 B
GDScript
extends Node2D
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
pass # Replace with function body.
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
var hasManipulatedZIndex = false
|
|
if $ShapeCast2D.is_colliding():
|
|
var nbCollisions = $ShapeCast2D.get_collision_count()
|
|
for n in range(nbCollisions):
|
|
var colider = $ShapeCast2D.get_collider(n) as Node2D
|
|
if colider != null and colider != get_parent():
|
|
(get_parent() as Node2D).z_index = max(colider.z_index+1, (get_parent() as Node2D).z_index)
|
|
hasManipulatedZIndex = true
|
|
if !hasManipulatedZIndex:
|
|
(get_parent() as Node2D).z_index = 100
|
|
$debugLabel.text = str(get_parent()) + " " + str((get_parent() as Node2D).z_index)
|