0

I have created a 3d button in ursina, but suppose we are a kilometer away from the button, we can still press it. Where is the logic in it? I would like to make the button clickable only when in a certain radius from it.

horror_gamemode = Button(parent = scene, model = 'cube', texture = None, color = color.black, highlight_color = color.dark_gray, scale = 1, position = (3, -49, 4), collider = 'mesh')
Lixt
  • 201
  • 4
  • 19

1 Answers1

0

If I got it right, you want to make a button not clickable when we are over, lets say, 100 meters. For that you can use ursina's distance function to calculate the position between the camera and the button and if it is less that 100 meters, then make it clickable, otherwise unclickable (you can use .disabled = False # or True).

Example:

from ursina import *
from ursina.prefabs import *


app = Ursina()

horror_gamemode = Button(parent = scene, model = 'cube', texture = None, color = color.black, highlight_color = color.dark_gray, scale = 1, position = (0, 0, 0), collider = 'mesh')


def some_random_func():
    print("HI")

    
def update():
    if (distance(camera, horror_gamemode) < 50):
        button.color = color.green
        button.disabled = False
        horror_gamemode.on_click = some_random_func
    else:
        button.color = color.red
        print(distance(horror_gamemode, camera))
        button.disabled = True
        horror_gamemode.on_click = None

EditorCamera()
        
app.run()
Lixt
  • 201
  • 4
  • 19