Ursina 3D engine. Part of the code with mouse.hovered doesn't work
Recently, I started to learn the ursina engine that allows you to work with 3D in Python. I followed the official tutorial for dummies - part of the code with mouse.hovered
doesn't work. What's the problem / What did I do wrong?
from ursina import *
import random
#Запуск игры
app = Ursina()
window.title = 'Ursina tutorial'
window.borderless = False
window.fullscreen = False
window.exit_button.visible = False
window.fps_counter.enabled = True
def rnd(min, max):
return random.randint(min, max)
#Обновление
def update():
delta = time.dt
if held_keys['a']:
for cube in cubes:
cube.rotation_y += delta * 50
if held_keys['d']:
for cube in cubes:
cube.rotation_y -= delta * 50
if held_keys['w']:
for cube in cubes:
cube.rotation_x += delta * 50
if held_keys['s']:
for cube in cubes:
cube.rotation_x -= delta * 50
if held_keys['up arrow']:
camera.position += (0, 0, 100 * delta)
elif held_keys['down arrow']:
camera.position -= (0, 0, 100 * delta)
if mouse.hovered_entity == cubes[0]: #Часть проблемного кода
info.visible = True
else:
info.visible = False
global offset
offset += delta * 0.5
setattr(cubes[0], "texture_offset", (0, offset)) #То к чему линкуем, параметр линка, (х,у)
def input(key):
if key == 'space':
for cub in cubes:
cub.color = color.rgb(rnd(0, 255), rnd(0, 255), rnd(0,255))
elif key == 'c':
cubes.append(Entity(parent = cube, model = 'cube', color = color.rgb(rnd(0, 255), rnd(0, 255), rnd(0,255)), scale = (rnd(1, 2), rnd(1, 2), rnd(1,2)), position = (rnd(-5, 5), rnd(-5, 5), rnd(-5,5))))
elif key == 'r':
cubes.append(Entity(model = 'cube', color = color.rgb(rnd(0, 255), rnd(0, 255), rnd(0,255)), scale = (rnd(1, 2), rnd(1, 2), rnd(1,2)), position = (rnd(-5, 5), rnd(-5, 5), rnd(-5,5))))
elif key == 'escape':
exit()
cubes = []
cube = Entity(model = 'cube', color = color.rgba(255, 255, 255, 128), scale = (2,6,1), texture = "water")
cubes.append(cube)
offset = 0.0
Text.size = 0.05
Text.default_resolution = 1080 * Text.size
info = Text(text = "lol")
info.x = 0.5
info.y = 0.4
info.background = True
info.visible = True
app.run()
0