Search Unity

Question Unable to play ricochet sound on bullet hit

Discussion in 'Audio & Video' started by ipubrich, Dec 31, 2020.

  1. ipubrich

    ipubrich

    Joined:
    Nov 10, 2020
    Posts:
    2
    Hi Guys,

    First post. Bit scared. I am learning to code and have been making a space shooter for the last 6 weeks. I keep getting stuck and so far reading forums and api docs has helped - until now.

    I am trying to play a sound when a laser bullet hits an enemy. I can get a spark to show and enemy health reduces so I know the collision is working.

    Here's the code I have assigned to my bullet model. It runs but I get no audio. I've tried as audiosource and audio clip but neither work. The clip is in the inspector :/


    public class bullet : MonoBehaviour
    {
    public AudioClip BulletAudio;

    private void OnTriggerEnter(Collider other)
    {
    if (other.CompareTag("Enemy"))
    {

    enemyTriggered = other.gameObject;
    AudioSource.PlayClipAtPoint(BulletAudio, enemyTriggered.transform.position);

    Destroy(this.gameObject);
    enemyTriggered.GetComponent<Enemy>().health -= enemyDamage;
    Rigidbody _ = Instantiate(LargeSquib, transform.position, transform.rotation);
    Destroy(_.gameObject, 5);


    healthpoints = enemyTriggered.GetComponent<Enemy>().health;
    UnityEngine.Debug.Log("Enemy hit! " + healthpoints);

    }
    }

    Video for reference :
     
  2. ipubrich

    ipubrich

    Joined:
    Nov 10, 2020
    Posts:
    2
    Dont see an option to delete this thread but I've asked in answers.