0

The function 'aimshot()' plays a sound and an animation in a certain spot (when aiming) and the same with the function 'noaimshot()' but when not aiming. For some reason, when I try to run these functions later in the 'def input(key)' function they do not work.

def aimshot():
        Audio("assets/GunShot.mp3")
        Animation("assets/spark", parent=camera.ui, fps=5, scale=.1, position=(.00, -.726), loop=False)

def noaimshot():
    Audio("assets/GunShot.mp3")
    Animation("assets/spark", parent=camera.ui, fps=5, scale=.1, position=(.34, -.54), loop=False)

def input(key):
    if key == 'escape':
        quit()

    if key == "q":
        aim.enable()
        noaim.disable()
        if key == "left mouse down":
           noaimshot()


    if key == "e":
        aim.disable()
        noaim.enable()
        if key == "left mouse down":
            aimshot()

The full code is here. NOTE: you will need to pip install ursina to run this.

from ursina import *
from random import uniform
from ursina.prefabs.first_person_controller import FirstPersonController

app = Ursina()
Sky()
player=FirstPersonController(y=10, origin_y=1)
ground=Entity(model='plane', scale=(20, 1, 20), color=color.lime, texture="white_cube",
              texture_scale=(20, 20), collider='box')


noaim = Entity(model="assets/gun.obj", parent=camera.ui, scale=.03, color=rgb(0, 0, 139), position=(.5, -.7),
            rotation=(-5, 5, 1))

aim = Entity(model="assets/gun.obj", parent=camera.ui, scale=.03, color=rgb(0, 0, 139), position=(.00, -.726),
                     rotation=(-5, 1, -1))
aim.disable()


def aimshot():
        Audio("assets/GunShot.mp3")
        Animation("assets/spark", parent=camera.ui, fps=5, scale=.1, position=(.00, -.726), loop=False)

def noaimshot():
    Audio("assets/GunShot.mp3")
    Animation("assets/spark", parent=camera.ui, fps=5, scale=.1, position=(.34, -.54), loop=False)

def input(key):
    if key == 'escape':
        quit()

    if key == "q":
        aim.enable()
        noaim.disable()
        if key == "left mouse down":
           noaimshot()


    if key == "e":
        aim.disable()
        noaim.enable()
        if key == "left mouse down":
            aimshot()

app.run()
Qstz D
  • 3
  • 3

0 Answers0