My code is this
CarSound.attributes.add('car sound', {
type: 'asset',
assetType: 'audio'
});
// initialize code called once per entity
CarSound.prototype.initialize = function() {
this.app.keyboard.on(pc.EVENT_KEYDOWN, this.onKeyDown, this);
this.app.keyboard.on(pc.EVENT_KEYUP, this.onKeyUp, this);
};
// update code called every frame
CarSound.prototype.update = function(dt) {
if (this.app.keyboard.wasPressed(pc.KEY_UP)) {
this.entity.sound.play('car sound');
but I don’t know how I would refer to the asset in my code
Hello @DeductedFlame24 ! If for example your attribute is like below, then you can refer to the asset with this.sound. But i’m not sure if you can play audio on the way you try to do right now.
CarSound.attributes.add('sound', {
type: 'asset',
assetType: 'audio'
});
1 Like
Hello @DeductedFlame24
I can add on from what @Albertos said
but the code should be replacing
DeductedFlame24:
type: 'asset',
should be asset: then whatever your code is lets say 43499272
asset: 43499272
like that.
To add a sound to your game and start the sound in your script I suggest to follow the steps in my other post with the exception of the last step.
1 Like
Thank you @Albertos and @Gabriel_Dobrzynski for the help I will try that
1 Like