34
edits
m (→Unity: formatting) |
m (→Example: Make an object jump on clapping: formatting) |
||
Line 116: | Line 116: | ||
c) Add Audio variables to your script. This script will also draw a circle depending on the audio volume. <br> | c) Add Audio variables to your script. This script will also draw a circle depending on the audio volume. <br> | ||
<source lang="javascript"> | <source lang="javascript"> | ||
float x; | float x; | ||
float y; | float y; | ||
Minim minim; | |||
Minim minim; | |||
AudioInput input; | AudioInput input; | ||
</source | </source> | ||
d) In the Setup() function add the values for the circle and create the audiotoolkit <br> | d) In the Setup() function add the values for the circle and create the audiotoolkit <br> | ||
<source lang="javascript"> | <source lang="javascript"> | ||
size (320, 240); | size (320, 240); | ||
smooth(); | smooth(); | ||
stroke (255, 25); | stroke (255, 25); | ||
noFill (); | noFill (); | ||
// Set start position | |||
x = 0; | // Set start position | ||
y = 20; | x = 0; | ||
minim = new Minim (this); | y = 20; | ||
input = minim.getLineIn (Minim.STEREO, 512); | |||
minim = new Minim (this); | |||
input = minim.getLineIn (Minim.STEREO, 512); | |||
background (0); | background (0); | ||
</source | </source> | ||
e) The draw() function will be the container of the circle’s size. It will only send the values to Unity if the circle is big enough. <br> | e) The draw() function will be the container of the circle’s size. It will only send the values to Unity if the circle is big enough. <br> | ||
<source lang="javascript"> | <source lang="javascript"> | ||
void draw () { | void draw () { | ||
int i =0; | int i =0; | ||
float dim = input.mix.level () * width;<br> | float dim = input.mix.level () * width;<br> | ||
if (dim >= 80){System.out.println("Loud enough: "+dim); | |||
OscMessage myMessage = new OscMessage("/"); | if (dim >= 80){System.out.println("Loud enough: "+dim); | ||
myMessage.add(dim); | OscMessage myMessage = new OscMessage("/"); | ||
myMessage.add(true); | myMessage.add(dim); | ||
oscP5.send(myMessage, myRemoteLocation);} | myMessage.add(true); | ||
</source | oscP5.send(myMessage, myRemoteLocation);} | ||
</source> | |||
f) When you are ready, press Play. <br> <br> | f) When you are ready, press Play. <br> <br> | ||
'''2. In Unity:''' <br> | '''2. In Unity:''' <br> | ||
Line 150: | Line 154: | ||
b) Open up the Osc Receiver Script. Define a new private variable. <br><br><source lang="javascript"> | b) Open up the Osc Receiver Script. Define a new private variable. <br><br><source lang="javascript"> | ||
private var moveSpeed : int = 0; | private var moveSpeed : int = 0; | ||
</source | </source> | ||
c) Create a new public function.<br> | c) Create a new public function.<br> | ||
<source lang="javascript"> | <source lang="javascript"> | ||
Line 157: | Line 161: | ||
moveSpeed = msgValue; | moveSpeed = msgValue; | ||
} | } | ||
</source | </source> | ||
d) In the Update() function add <br> | d) In the Update() function add <br> | ||
<source lang="javascript"> | <source lang="javascript"> | ||
var go = GameObject.Find(gameReceiver); | var go = GameObject.Find(gameReceiver); | ||
go.transform.Translate(0, moveSpeed, 0); | go.transform.Translate(0, moveSpeed, 0); | ||
</source | </source> | ||
e) In the AllMessageHandler() function add <br> | e) In the AllMessageHandler() function add <br> | ||
<source lang="javascript"> | <source lang="javascript"> | ||
Line 169: | Line 173: | ||
MoveObject(msgValue); | MoveObject(msgValue); | ||
break;} | break;} | ||
</source | </source> | ||
f) When you are ready, press Play. | f) When you are ready, press Play. | ||
edits