- Home /
Audio Velocity
Hi! How can I increase the audio velocity, when i press a key? Any help is good! :)
Thank you
Are you asking about increasing/decreasing the speed of audio play?
Yes. but increasing the reproduction speed audio, non the volume sorry.
Answer by iamvishnusankar · Feb 11, 2014 at 09:15 PM
If you're talking about Audio pitch. Try this code
public float _audioSpeed = 1.2f;
void Start()
{
audio.pitch = _audioSpeed;
}
You could change it from inspector also.
or Use a horizontal ScrollBar to change the pitch
public float hSliderValue = 0.0;
function OnGUI ()
{
hSliderValue = GUI.HorizontalSlider (Rect (25, 25, 100, 30), hSliderValue, -3.0f, 3.0f);
audio.pitch = hSliderValue ;
}
Ok, I tried so, I put the AudioClip, but how call it in the script? and in this script, when I press a key, the audio playback speed increases? I would like this.. sorry for my english. ;)
using UnityEngine;
using System.Collections;
public class Audio : $$anonymous$$onoBehaviour {
public float aspeed = 1.2f;
public AudioClip $$anonymous$$otore;
// Use this for initialization
void Start ()
{
audio.pitch = aspeed;
}
// Update is called once per frame
void Update ()
{
if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.Z))
{
aspeed += 1;
}
if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.X))
{
aspeed -= 1;
}
}
}
Try rewriting your script as follows. I hope this will solve your problem.
using UnityEngine;
using System.Collections;
public class Audio : $$anonymous$$onoBehaviour
{
public AudioClip $$anonymous$$otore;
void Start()
{
audio.clip = $$anonymous$$otore;
}
// Update is called once per frame
void Update ()
{
if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.Z))
{
audio.pitch +=0.2f;
}
if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.X))
{
audio.pitch -=0.2f;
}
}
}
hmhmh ok it work! two more questions: 1) how can I set the pitch max-limit at 3 and the $$anonymous$$imum at 0?
2) i added the audio source in unity editor with the current audio, but if i don't click on "play awake" the audio dosn't start, but i would like that it starts when I press a key.
How can i put in the script the auto-play at 0.0?
thank you, paolo
Add this code on Update() fucntion
//Clamp audio pitch between 0 & 3
$$anonymous$$athf.Clamp(audio.pitch,0f,3f)
Add this code on Start() to play audio without clicking awake
void Start()
{
if (!audio.playOnAwake) audio.Play();
}
For further info refer Unity documentation about AudioSoure
Leave an acceptance if this solve your problem. Cheers. :)
ok the firts one work, but the second no.. why? :P I put it here:
void Update ()
{
$$anonymous$$athf.Clamp (audio.pitch, 0f, 3f);
if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.Z))
{
audio.pitch +=0.2f;
}
if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.X))
{
audio.pitch -=0.2f;
}
}
i don't know where i can find my solution problem in script reference.. :/
Your answer
Follow this Question
Related Questions
play sound when player reaches a certain speed 1 Answer
How can I use Unity's Doppler effect with high velocity objects? 1 Answer
How I can change the speed of an object with the speed of sound so they are evenly matched? 2 Answers
Velocity powered rigidbody on a moving platform without parenting. 3 Answers