from ursina import * import keyboard from ursina.prefabs.first_person_controller import FirstPersonController app = Ursina() modes = ["textures","models","colors"] cmode = "textures" allcolors = ["red","green","blue","white","black","gray","orange","yellow","pink","cyan","magenta"] ccolor = "orange" inventory = "normal" currentmodel = "cube" modelsssss = ["cube","sphere","plane"] texturessss = ["white_cube", "brick","grass","noise","circle","radial_gradient","normal"] Sky() player = FirstPersonController() player.disable() boxes = [] b1 = Button(text="Start", color=color.azure, text_color=color.green, scale=1, icon="sword", text_origin=(-0.5,0)) b2 = Text("A") b4 = Text("C") b3 = Text("B") b3.position = Vec3(0, -0.38,0) b3.text = cmode b2.position = Vec3(0, -0.4, 0) b2.text = inventory b4.text = ccolor b4.position = Vec3(0, -0.42,0) def onclick(): player.enable() destroy(b1) window.fullscreen = True b1.on_click = onclick def toggle_player(): player.enabled = not player.enabled def modechange(): global cmode print("a") indexx = modes.index(cmode) cmode = modes[(indexx + 1) % len(modes)] b3.text = cmode if cmode == "models": b2.text = currentmodel keyboard.on_press_key('esc', lambda _: toggle_player()) keyboard.on_press_key('r', lambda _: modechange()) # Move input function outside the loop def input(key): global currentmodel global inventory global ccolor if key == 'scroll up': print("scrolled up") if cmode == "textures": index = texturessss.index(inventory) inventory = texturessss[(index + 1) % len(texturessss)] if cmode == "models": indexx = modelsssss.index(currentmodel) currentmodel = modelsssss[(indexx + 1) % len(modelsssss)] if key == 'scroll down': print("scrolled down") if cmode == "textures": index = texturessss.index(inventory) inventory = texturessss[(index - 1) % len(texturessss)] if cmode == "models": indexx = modelsssss.index(currentmodel) currentmodel = modelsssss[(indexx - 1) % len(modelsssss)] if cmode == "textures": b2.text = inventory if cmode == "models": b2.text = currentmodel for box in boxes: if box.hovered: if key == 'right mouse down': new_box = Button( parent=scene, model=currentmodel, origin_y=0.5, texture=inventory, color= color.ccolor highlight_color= color.lime, position=box.position + mouse.normal ) boxes.append(new_box) if key == 'left mouse down': boxes.remove(box) destroy(box) # Create boxes grid for n in range(25): for k in range(25): box = Button( parent=scene, model='cube', origin_y=0.5, texture='white_cube', color=color.orange, highlight_color=color.lime, position=(k, 0, n) ) boxes.append(box) app.run()