Coin collision sound effect not working!!!

Updated on October 8, 2017 in [D] Game Dev. gossip
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on October 8, 2017

I have already programmed my coin to be a coin but when i went to program its sound effects i had a little issue with it. I wanted when i hit my coin to play this sound effect but i get an error can anybody help me please. Here is my script and my errors:


[/ using UnityEngine;
using System.Collections;

public class PlayerCoinSFX : MonoBehaviour {

    public AudioClip[] audioClip;

    void OnTriggerEnter(Collider other)
    {
        if (other.transform.tag == "Coin")
        {
            ScoreTextScript.coinAmount += 1;
            PlaySound(0);
            Destroy(other.gameObject);
        }
    }

    void PlaySound(int clip)
    {
        audio.clip = audioClip[clip];
        audio.Play();
    }
}
]

 

errors:

    1. Assets/PlayerCoinSFX.cs(20,9): error CS1061: Type `UnityEngine.Component' does not contain a definition for `clip' and no extension method `clip' of type `UnityEngine.Component' could be found. Are you missing an assembly reference?

 

    1. Assets/PlayerCoinSFX.cs(21,9): error CS1061: Type `UnityEngine.Component' does not contain a definition for `Play' and no extension method `Play' of type `UnityEngine.Component' could be found. Are you missing an assembly reference?

 

  • Liked by
Reply
0 on October 8, 2017

It seems that you forgot to set an AudioSource.

public AudioSource audio;

 

  • Liked by
Reply
Cancel