Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | mnzz123 |
I am making a game where you clean trash out of space. I want to make it so that when you click the trash it moves to a randomly different place each time clicked with the mouse
make new node with type texture button
megatron | 2023-03-14 06:08
attach newly created node with script (create new script)
megatron | 2023-03-14 07:12
select newly created node, select node tab (at right upper corner of the screen, right of inspector tab)
megatron | 2023-03-14 09:04
select pressed(), then select connect
type _on_pressed, below receiver method
select connect
megatron | 2023-03-14 09:05
open node script, select all, and copy-paste code below:
extends TextureButton
var screen_width = 1152
var screen_height = 648
func _on_pressed():
var random = RandomNumberGenerator.new()
var new_position = Vector2(random.randf_range(0, screen_width), random.randf_range(0, screen_height))
position = new_position
megatron | 2023-03-14 09:08
select run button to try if its working
megatron | 2023-03-14 09:12