Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jister · Dec 30, 2011 at 06:40 PM · audiolooping

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;
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

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

Why can't I add a script to an object? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges