GMU:Tutorials/Networking/Controlling Unity with Processing: Difference between revisions

From Medien Wiki
m (→‎Unity: more screenshots. (ok just one))
Line 94: Line 94:
a) Install an additional library for sound. Click on ''Tools'' – ''Add Tools'' – Choose ''Libraries'' – Search for Minim and install it. <br>
a) Install an additional library for sound. Click on ''Tools'' – ''Add Tools'' – Choose ''Libraries'' – Search for Minim and install it. <br>
b) To your imported Libraries add <br>
b) To your imported Libraries add <br>
<code>
<source lang="javascript">
import ddf.minim.*;  
import ddf.minim.*;  
</code>
</source>
<br>
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><code>
<source lang="javascript">
float x;<br>
float x;<br>
float y;<br>
float y;<br>
Minim minim;<br>
Minim minim;<br>
AudioInput input;</code> <br>
AudioInput input;
d) In the Setup() function add the values for the circle and create the audiotoolkit <br><code>
</source> <br>
d) In the Setup() function add the values for the circle and create the audiotoolkit <br>
<source lang="javascript">
size (320, 240);<br>
size (320, 240);<br>
smooth();<br>
smooth();<br>
Line 113: Line 115:
minim = new Minim (this);<br>
minim = new Minim (this);<br>
input = minim.getLineIn (Minim.STEREO, 512);<br>
input = minim.getLineIn (Minim.STEREO, 512);<br>
background (0);</code> <br>
background (0);
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><code>
</source> <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">
void draw () {<br>
void draw () {<br>
int i =0;<br>
int i =0;<br>
Line 122: Line 126:
myMessage.add(dim);<br>
myMessage.add(dim);<br>
myMessage.add(true);<br>
myMessage.add(true);<br>
oscP5.send(myMessage, myRemoteLocation);}</code> <br>
oscP5.send(myMessage, myRemoteLocation);}
</source> <br>
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>
a) Create an object in Unity. Drag this object onto the gameReceiver of your Osc Receiver Script. This object is now the gameReceiver and will behave as you define in the Osc Receiver script.  <br>
a) Create an object in Unity. Drag this object onto the gameReceiver of your Osc Receiver Script. This object is now the gameReceiver and will behave as you define in the Osc Receiver script.  <br>
b) Open up the Osc Receiver Script.  Define a new private variable.<br><code>
b) Open up the Osc Receiver Script.  Define a new private variable. <br><br><source lang="javascript">
private var moveSpeed : int = 0; </code> <br>  
private var moveSpeed : int = 0;
c)  Create a new public function.<br><code>
</source> <br>  
public function MoveObject(msgValue) : void <br>
c)  Create a new public function.<br>
{<br>
<source lang="javascript">
moveSpeed = msgValue; <br>
public function MoveObject(msgValue) : void
}</code> <br>
{
d)  In the Update() function add <br><code>
moveSpeed = msgValue;
}
</source> <br>
d)  In the Update() function add <br>
<source lang="javascript">
var go = GameObject.Find(gameReceiver);<br>
var go = GameObject.Find(gameReceiver);<br>
go.transform.Translate(0, moveSpeed, 0); </code> <br>
go.transform.Translate(0, moveSpeed, 0);  
e) In the AllMessageHandler() function add <br><code>
</source> <br>
switch (msgAddress){<br>
e) In the AllMessageHandler() function add <br>
default:<br>
<source lang="javascript">
MoveObject(msgValue);<br>
switch (msgAddress){
break;}</code> <br>
default:
  MoveObject(msgValue);
  break;}
</source> <br>
f) When you are ready, press Play.
f) When you are ready, press Play.