Hello, I’m having a strange error with sound effect playback in the block breaker game. I’ve done all the steps for boing and it works properly. However, it does not seem to be working with the crack sound. Well, I think it’s not?
What I mean is that the sound I imported I know is audible and loud, and when I apply the crack, there’s like a 50/50 chance it plays on hitting a brick and on the ones it does play it’s been muffled to barely being audible. I tried with both mono and stereo audio tracks and I have the same issue both times. Even more strange is the fact that everytime the ball hits the brick, a “one shot audio” appears in the hierarchy. So it’s being called I think, just not heard? I’m using Unity 5.3, sorry I know it says to use the other one but I already started with this one.
Here’s my Brick code for reference:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Brick : MonoBehaviour {
public AudioClip crack;
public Sprite[] hitSprites;
public static int breakableCount;
private int timesHit;
private LevelManager levelManager;
private bool isBreakable;
// Use this for initialization
void Start () {
isBreakable = (this.tag == "Breakable");
if (isBreakable) {
breakableCount = breakableCount + 1;
}
timesHit = 0;
levelManager = GameObject.FindObjectOfType<LevelManager> ();
}
// Update is called once per frame
void Update () {
}
void OnCollisionExit2D(Collision2D collider){
AudioSource.PlayClipAtPoint (crack, transform.position);
if (isBreakable) {
HandleHits ();
}
}
void HandleHits(){
timesHit = timesHit + 1;
int maxHits = hitSprites.Length + 1;
if (timesHit >= maxHits) {
breakableCount--;
levelManager.BrickDestroyed ();
Destroy (gameObject);
} else {
LoadSprites ();
}
}
void LoadSprites(){
int spriteIndex = timesHit - 1;
if(hitSprites[spriteIndex]){
this.GetComponent<SpriteRenderer> ().sprite = hitSprites[spriteIndex];
}
}
//TODO Remove this method once we can actually win.
void SimulateWin(){
levelManager.LoadNextLevel ();
}
}