Hi. I’m trying to create a level in my fps. In it you must collect 12 C4. Im trying to make that every 4 bombs the music changes to more intensive. Im having a problem. It plays the sound kinda like “stacked” when i collect 1 C4. But when i collect the second one it plays it normally. But it doesnt change the music. Can anyone help me? Heres the code:
using UnityEngine;
using System.Collections;
public class BombCollect : MonoBehaviour
{
public GameObject Bomb;
public AudioClip BombGrab;
public AudioClip Bomb1;
public AudioClip Bomb2;
public AudioClip Bomb3;
public int BombsWin = 0;
void Update ()
{
RaycastHit hit;
var fwd = transform.TransformDirection (Vector3.forward);
if (Input.GetKey(KeyCode.E)) {
if (Physics.Raycast(transform.position, fwd, out hit, 3)) {
if (hit.collider.tag == "Respawn") {
audio.Clip = BombGrab;
bombWin +=1;
audio.Play ();
Destroy(hit.transform.gameObject);
}
else Debug.Log ("Not a bomb.");
}
else Debug.Log ("Nothing found.");
}
if(bombWin == 12){
Debug.Log ("U WON");
}
if(bombWin == 1)
{
audio.clip = Bomb1;
audio.Play();
}
if(bombWin == 3){
{
audio.clip = bomb3;
audio.Play();
}
}
if(bombWin == 6)
{
audio.clip = bomb3;
audio.Play ();
}
}
}