Search Unity

Updating Microphone Script

Discussion in 'Audio & Video' started by michaelmolitchhou, Nov 7, 2015.

  1. michaelmolitchhou

    michaelmolitchhou

    Joined:
    Nov 7, 2015
    Posts:
    1
    So, I made a crappy game in 2012 in which sound from the microphone moved the game's camera forward. Only, then, to do it, I had to use a separate Processing program to do it and had three scripts capturing that input, etc. I just opened it up again and can't remember how it worked and want to replace that Processing stuff with a simpler MicrophoneInput script taking advantage of native Unity capabilities. I was a beginner in 2012 and now I'm even rustier. Would anyone be able to help me convert this script into something that relies on a built-in MicInput script?

    The old scripts relying on Processing were related to these variables and scripts: UDPPacketIO, OSCReceiver, OSCscript.

    Let me know if there's any help out there or if this is all too confusing to even understand! Thanks so much!

    var rotateSensitivity : float = 4.0;
    var Sphere : Transform;
    var Camera : Transform;
    //var moveSpeed : float = 50.0;
    var controlCurve : ControlCurve;
    private var endlevel : boolean = false;
    var OSCobject : GameObject;

    /*
    public var RemoteIP : String = "127.0.0.1";
    public var SendToPort : int = 7000;
    public var ListenerPort : int = 7001;
    private var handler : Osc;

    private var f_val : float;
    */

    function Awake ()
    {

    // In order to make the feel of the player controls
    // consistent in all levels, we set this property in awake.
    // This way, each level's instance of the camera can inherit response
    // curve that has been set up in the Prefab called "Control Curve"

    // Note: To edit the master response curve, select the
    // "ControlCurve" Prefab in the Resources folder, and
    // select GameObject->Edit Response Curves from the menubar


    // Set iPhone to widescreen mode

    /*
    var udp : UDPPacketIO = GetComponent("UDPPacketIO");
    udp.init(RemoteIP, SendToPort, ListenerPort);
    handler = GetComponent("Osc");
    handler.init(udp);


    handler.SetAddressHandler("/data", Data);
    */


    Screen.orientation = Screen.orientation.LandscapeLeft;
    }

    function Update ()
    {
    // Move the camera and children forward
    updateButton();
    endlevel = false;
    //print(f_val);

    }

    function updateButton(){
    var OSCscript1 = OSCobject.GetComponent("OSCReceiver");
    if(OSCscript1.fval > 1){
    moving = true;
    }

    if (moving && (endlevel==false)){
    updatePicker();
    }
    }

    function updatePicker(){
    var OSCscript = OSCobject.GetComponent("OSCReceiver");
    transform.Translate (0,0, Time.deltaTime * (OSCscript.fval*10));

    if (Camera.transform.position.z > Sphere.transform.position.z){
    endlevel = true;
    moving = false;
    }

    if (endlevel){
    StopCamera();
    }
    }

    function StopCamera(){
    var OSCscript1 = OSCobject.GetComponent("OSCReceiver");

    if(OSCscript1.fval){
    endlevel = true;
    moving = false;
    }

    print ("hello");

    moveSpeed = 0;
    Sphere.transform.position = Vector3(0,0,Camera.transform.position.z + 10);

    yield WaitForSeconds (10);
    Application.LoadLevel("level 2");
    //transform.Translate (0,0,0);

    }

    /*
    public function Data(oscMessage : OscMessage) : void
    {
    f_val = oscMessage.Values[0];
    }

    */