Skip to content

Commit

Permalink
Audio effect of shots
Browse files Browse the repository at this point in the history
  • Loading branch information
JI0PATA committed Nov 14, 2023
1 parent 641ed67 commit aed0be8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Weapon.jsx
Expand Up @@ -5,6 +5,7 @@ import {useEffect, useRef, useState} from "react";
import {useFrame, useLoader} from "@react-three/fiber";
import {usePointerLockControlsStore} from "./App.jsx";
import {create} from "zustand";
import SingleShootAK47 from "./assets/sounds/single-shoot-ak47.wav";
import FlashShoot from "./assets/images/flash_shoot.png";

const SHOOT_BUTTON = parseInt(import.meta.env.VITE_SHOOT_BUTTON);
Expand All @@ -25,6 +26,8 @@ export const Weapon = (props) => {
const setIsAiming = useAimingStore((state) => state.setIsAiming);
const weaponRef = useRef();

const audio = new Audio(SingleShootAK47);

const texture = useLoader(THREE.TextureLoader, FlashShoot);

const [flashAnimation, setFlashAnimation] = useState(null);
Expand Down Expand Up @@ -92,6 +95,8 @@ export const Weapon = (props) => {
const startShooting = () => {
if (!recoilAnimation) return;

audio.play();

recoilAnimation.start();
flashAnimation.start();
}
Expand Down
Binary file added src/assets/sounds/single-shoot-ak47.wav
Binary file not shown.

0 comments on commit aed0be8

Please sign in to comment.