i have this problem when i try to shoot sound dont play how do i fix it
this is my code
using UnityEngine;
public class Gun : MonoBehaviour {
public float damage = 10f;
public float range = 100f;
public float firerate = 15f;
public float impactforce = 80f;
public Camera fpsCam;
public ParticleSystem muzzleflash;
public GameObject impact;
public AudioSource gunshotsound;
private float nextTimeToFire = 0f;
// Update is called once per frame
void Update()
{
if (Input.GetButtonDown("Fire1") && Time.time >= nextTimeToFire)
{
nextTimeToFire = Time.time + 1f / firerate;
Shoot();
}
}
void Shoot()
{
gunshotsound.Play();
muzzleflash.Play();
RaycastHit Hit;
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out Hit, range))
{
Debug.Log(Hit.transform.name);
target target = Hit.transform.GetComponent<target>();
{
if (target != null)
{
target.TakeDamage(damage);
}
}
}
if(Hit.rigidbody != null)
{
Hit.rigidbody.AddForce(-Hit.normal * impactforce);
}
GameObject impactGO = Instantiate(impact, Hit.point, Quaternion.LookRotation(Hit.normal));
Destroy(impactGO, 1f);
}
}
Comment
gunshotsound.Play();
This should play the sound loaded on your audiosource.
OPtion 1- no clip loaded there
Option 2 volume lo
Option 3 clip has no sound
$$anonymous$$ybe more options.. But, go step by step.. Is the line beeiong executed? its the audiocource correct, is the clip corret..
Your answer
Follow this Question
Related Questions
how create sound effect based on speed ? 0 Answers
Standard FPS Controller - Sounds Cancelling One Another 0 Answers
AudioClip sounding good in editor, but bad in IOS/Android (sounds like a vintage movie robot) 0 Answers
sound delay 0 Answers
How to Play sequentially more than one AudioSource in one game object ? 1 Answer