- Home /
turning audio on and off
I am currently trying to make a script that goes along with a slow down time script, that when I press v it slows down time, then when i press v again it speeds up time back to normal. I would like a way to play an audio file to go along with each slow down and speed up, but the audio files have to be different for slow down and speed up. Thanks!
Time slower Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TimeSlower : MonoBehaviour {
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown (KeyCode.V)) {
if (Time.timeScale == 1.0F)
Time.timeScale = 0.4F;
else
Time.timeScale = 1.0F;
Time.fixedDeltaTime = 0.02F * Time.timeScale;
}
}
}
Answer by Brogan89 · Jun 15, 2017 at 10:45 PM
Have you tried looking in the Learn section? https://unity3d.com/learn/tutorials/topics/audio/adding-music-your-game?playlist=17096
its not exactly music its more like a sound effect. but it also needs to change from when time slows down and when time speeds up, the audio clip is only 2 seconds
there is also lessons on sound effects.
Store the AudioClips in public variables, and use AudioSource component to trigger whenever you press the V key. AudioSource.PlayOneShot(AudioClip);
You can also slow and speed up Audio in script using AudioSource.$$anonymous$$ch.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
I want to play an Audio Sound for a character while running. 0 Answers