• 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 tingtinglyy · Apr 28, 2017 at 04:05 PM · animationanimatormicrophone

How to use mic input to start and stop animation?

Hi im am really new with unity and i have a performance in a few weeks.

I imported a dancing model, but i want the model to start dancing when the mic input detects sound and stop when there is no sound. My lecturer provided a tutorial on using the mic input to cause an object to change its size through the mic but that isn't really what i need. I will attach the code for the size microphone effector but i would really appreciate it if someone can provide me with a code to get the animation to start and stop instead of changing the size ... >.<

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class MicrophoneEffector : MonoBehaviour {

 private Vector3 scaledVector;
 private Vector3 originalVector;
 // Use this for initialization
 void Start () {
     originalVector = new Vector3 (1, 1, 1);    
 }

 // Update is called once per frame
 void Update () {

     if (Mathf.Sqrt(MicrophoneInput.MicLoudness) > 0.07) {
         //Debug.Log (Mathf.Sqrt(MicrophoneInput.MicLoudness));
         scaledVector = new Vector3 ((Mathf.Sqrt (MicrophoneInput.MicLoudness) * 2), (Mathf.Sqrt (MicrophoneInput.MicLoudness) * 2), (Mathf.Sqrt (MicrophoneInput.MicLoudness) * 2));
         this.gameObject.transform.localScale += scaledVector;
         StartCoroutine(WaitForABit());
     }


 }

 IEnumerator WaitForABit(){
     yield return new WaitForSeconds (1);
     this.gameObject.transform.localScale = Vector3.Slerp(originalVector, scaledVector, 1);

 }

}

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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

2D Animation does not start 1 Answer

Help!Bug with animation blend.When I press the opposite buttons almost simultaneously (A + D or W + S) my animation is buggy 0 Answers

How to switch between procedural animation to Mecanim / Animator animations 0 Answers

Problem with connecting between the Walk mode and Idle mode, they are mix 0 Answers

Character animation with Animator isn't working. 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges