- Home /
audio synthesizer in unity?
hey I'm trying to make a organ that makes a kind of rainbow with colors when you play. by mapping 12 notes and 12 colors to 12 keys. so far i have the color working and an audioclip that plays, but i'd like it to keep playing the note if the key is held down. i could do this with a perfect loop of the note but then it loses all emotion kind of. i'd like the crescendo to stay and loop the audio clip somewhere in the middle so that I keep the fade in and out when the key is pressed or released. anyway of doing this?
this is my current code:
using UnityEngine;
using System.Collections;
public class PUZZLE : MonoBehaviour {
public KeyCode key1;
public AudioClip note1;
public Color defaultColor = Color.white;
public Color newColor = Color.red;
public float speed;
void Start(){
Mesh mesh = GetComponent<MeshFilter>().mesh;
Color[] colors = new Color[mesh.vertices.Length];
int i = 0;
while (i < mesh.vertices.Length) {
colors[i] = defaultColor;
i++;
}
mesh.colors = colors;
}
void Update () {
Mesh mesh = GetComponent<MeshFilter>().mesh;
Color[] colors = mesh.colors;
int i = 0;
while (i < mesh.vertices.Length) {
if(Input.GetKey(key1)){
audio.PlayOneShot(note1);
colors[i] = Color.Lerp(colors[i], newColor, speed * Time.deltaTime);
} else {
colors[i] = Color.Lerp(colors[i], defaultColor, speed * Time.deltaTime);
}
i++;
}
mesh.colors = colors;
}
}
Answer by aldonaletto · Dec 30, 2011 at 07:49 PM
You don't have such level of control in Unity - at least up to now. You can try something like this keyboard piano posted in another question.
Your answer
Follow this Question
Related Questions
cant stop my animation 0 Answers
Audio Help! 1 Answer
help sound on collision when key down 2 Answers
Audio script doesn't work 1 Answer