- Home /
Question by
gimoj · Jul 19, 2014 at 04:03 PM ·
audiosounddistortion
how to fix 2d sound distortion?
I have 2 audiosources in my gameobject. The first one play whenever I hit an enemy and it goes the way it should but the second one( plays when the player dies) gets distorted. I think I read somewhere that the reason is that it starts to play after every frame but I put a boolean to try and avoid that. Is there a way to fix this?
void Start ()
{
playclip2 = false;
AudioSource[] sounds = GetComponents<AudioSource>();
clip1 = sounds[0];
clip2 = sounds[1];
}
void Update ()
{
walking = true;
}
void FixedUpdate ()
{
GroundCheck ();
if (grounded == false || dragged == true)
{
float h = Input.GetAxis ("Mouse X");
if (h > 0 && !facingRight)
Flip ();
else if (h < 0 && facingRight)
Flip ();
}
if (grounded == true)
{
if (walking == true)
{
walker ();
}
Collider2D[] frontHits = Physics2D.OverlapPointAll (frontCheck.position);
foreach (Collider2D c in frontHits) {
// If any of the colliders is an Obstacle...
if (c.tag == "DirectionTrigger") {
Flip ();
break;
}
if (c.tag == "Enemy") {
if (enemyhit == false){
if (c.gameObject.GetComponent<Bugbot> ().destructionImminent == false)
{
animator.SetTrigger("swat");
walking = false;
clip1.Play();
}
}
break;
}
}
}
if(HP <= 0 && !dead)
{
// ... call the death function.
Death ();
playclip2 = true;
StartCoroutine(delayAnim());
}
if(playclip2 && !audio.isPlaying)
{
playclip();
}
}
public void playclip()
{
clip2.Play();
}
Comment
Best Answer
Answer by gimoj · Jul 19, 2014 at 04:32 PM
Nevermind, I got it to work now. All I had to do is change line 60 to: if(HP <= 0 && !dead && !playclip2)
Your answer
Follow this Question
Related Questions
help with multiple sounds 0 Answers
Audio doesn't play 1 Answer
NGUI Volume And Quality Controle With Sliders Not working 1 Answer
Play from a variety of sounds? 1 Answer
multiple sounds, sound....sucky 0 Answers