How to play a random sound in different if statements? example when i will be in 0<25 play some sound one or twice, when value(slider) is in 25 to 40 play more sounds in the row... i wanna simulate breather but i think this script is too much to handle for me.. Sound is playing only once and only when i start game. Looks like Unity read only first If statement and after will nothing happen...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayingSoundsystem: MonoBehaviour
{
private AudioSource breath_sound;
[SerializeField]
private AudioClip[] breath_Clip;
private AudioClip breath;
public float volume_Min, volume_Max;
public GameObject Textvalue;
public Slider mainSlider;
public GameObject Spotlight;
public GameObject blur;
private void Start()
{
breath_sound = GetComponent<AudioSource>();
}
private void Update()
{
Textvalue.GetComponent<Text>().text = mainSlider.value.ToString();
if (Spotlight.GetComponent<Light>().enabled == false)
{
mainSlider.value += 1*Time.deltaTime;
}
else
{
mainSlider.value -= 0.5f * Time.deltaTime;
}
if (mainSlider.value <= 25)
{
breath_sound.volume = Random.Range(volume_Min, volume_Max);
breath_sound.clip = breath_Clip[Random.Range(0, breath_Clip.Length)];
breath_sound.PlayOneShot(breath_sound.clip);
//Play Random Sound from 13 different one's
}
if (mainSlider.value > 25 && mainSlider.value <= 40)
{
int index = Random.Range(0, breath_Clip.Length);
breath = breath_Clip[index];
breath_sound.clip = breath;
breath_sound.Play();
}
if (mainSlider.value > 40 && mainSlider.value <= 60)
{
breath_sound.volume = Random.Range(volume_Min, volume_Max);
breath_sound.clip = breath_Clip[Random.Range(0, breath_Clip.Length)];
breath_sound.PlayOneShot(breath_sound.clip);
}
if (mainSlider.value > 60 && mainSlider.value <= 85)
{
breath_sound.volume = Random.Range(volume_Min, volume_Max);
breath_sound.clip = breath_Clip[Random.Range(0, breath_Clip.Length)];
breath_sound.PlayOneShot(breath_sound.clip);
}
if (mainSlider.value > 85 && mainSlider.value < 100)
{
breath_sound.volume = Random.Range(volume_Min, volume_Max);
breath_sound.clip = breath_Clip[Random.Range(0, breath_Clip.Length)];
breath_sound.PlayOneShot(breath_sound.clip);
}
if (mainSlider.value == 100)
{
}
}
private void OnTriggerEnter(Collider other)
{
if(other.gameObject.CompareTag ("Jumpscare"))
{
mainSlider.value += 5;
}
}
public void SubmitSliderSetting()
{
Debug.Log(mainSlider.value);
}
}
Aucun commentaire:
Enregistrer un commentaire