42 lines
914 B
GDScript
42 lines
914 B
GDScript
extends StaticBody3D
|
|
|
|
@onready var beds = preload("res://Scenes/Prefabs/DoubleBeds.tscn")
|
|
|
|
var areas
|
|
var previewObject: Node3D
|
|
var is_placed = false
|
|
func _ready() -> void:
|
|
areas = get_children()
|
|
Global.exit_build_mode.connect(_on_exit_build_mode)
|
|
|
|
|
|
func _input_event(camera: Camera3D, event: InputEvent, event_position: Vector3, normal: Vector3, shape_idx: int) -> void:
|
|
if event.is_action_pressed("mouse_click") and Global.build_mode:
|
|
place_object()
|
|
|
|
|
|
|
|
func _mouse_enter() -> void:
|
|
if !is_placed and Global.build_mode:
|
|
show_preview()
|
|
|
|
func _mouse_exit() -> void:
|
|
if !is_placed and Global.build_mode:
|
|
hide_preview()
|
|
|
|
func show_preview():
|
|
previewObject = beds.instantiate()
|
|
areas[0].add_child(previewObject)
|
|
|
|
func hide_preview():
|
|
if is_placed != true:
|
|
if previewObject != null:
|
|
previewObject.queue_free()
|
|
|
|
func place_object():
|
|
is_placed = true
|
|
|
|
|
|
func _on_exit_build_mode():
|
|
hide_preview()
|