Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | potatobanana |
how to check if something at top of tile?
i make one type cell can spawn tower/scene, but i dont want it keep spawn at same position after i spawn once. how should i stop it?
this my video https://youtu.be/6K1L4NJPf_w
this my code
export (PackedScene) var tower_1
func _unhandled_input(event: InputEvent) -> void:
var mouse_pos = get_viewport().get_mouse_position()
var tile_pos = world_to_map(mouse_pos)
var tile_cell_at_mouse_pos = get_cellv(tile_pos)
if event.is_action_pressed("Lclick"):
if tile_cell_at_mouse_pos != INVALID_CELL: # if tile cell is full with tile
if tile_cell_at_mouse_pos == 0:# transform normal grass tile to dirt tile
set_cellv(tile_pos,randi() % 2 + 1)
if tile_cell_at_mouse_pos == 1 : # buy tower ballista
var tower_instance = tower_1.instance()
tower_instance.global_position = map_to_world(tile_pos) + cell_size/2
tower_instance.connect("shoot",get_parent().get_parent(),"_on_tower_Ballista_shoot")
add_child(tower_instance)