The question is answered, right answer was accepted
[SOLVED] My sound effect code isnt working
I have already seen this http://docs.unity3d.com/ScriptReference/AudioSource.PlayOneShot.html and know that it works... but i wanna use a box collider trigger for experimenting since im new to learning. Also this is a pong game.
[Problem] The game still playable but the audioclip i drag into the script doesnt play when the ball hits the trigger
Here is my code
using UnityEngine;
using System.Collections;
public class Sound : MonoBehaviour {
public AudioClip paddle1;
AudioSource audio;
void Start () {
audio = GetComponent<AudioSource>();
}
void OnTrggerEnter(Collider other) {
audio.PlayOneShot (paddle1, 0.7F);
}
}
Error im getting in console Assets/Scripts/Sound.cs(6,21): warning CS0108: Sound.audio' hides inherited member
UnityEngine.Component.audio'. Use the new keyword if hiding was intended
Ok seems i fixed it by just copying and pasting the code and changing it to Trigger
using UnityEngine;
using System.Collections;
public class Sound : $$anonymous$$onoBehaviour {
public AudioClip impact;
AudioSource audio;
void Start() {
audio = GetComponent<AudioSource>();
}
void OnTriggerEnter() {
audio.PlayOneShot(impact, 0.7F);
}
}
Would still like to know what was wrong with $$anonymous$$e tho $$anonymous$$
Follow this Question
Related Questions
How to get the audiosource to work? 1 Answer
How to get mix values of paint textures on terrain? 0 Answers
How to control Music vs SFX vol using Master Mixer 0 Answers
Play sound on particle death C# 0 Answers