In the intended game, the user have to listen where the sound come from and shoot towards that direction. To judge whether the player make a correct action and give them audio feedback, I choose to combine Arduino with Unity 3D. In this way, i thinkg the Unity could know which IR receiver received the siganl and then give corresponding feedback. For example, when zombie's attacking sound effect comes from left, a zombie's getting hurt sound effect can be plyaed if the player shoots towards right, but a human's getting hurt sound effect can be played if player shoots at other directions. Now, the first task for me is to figure out how to let Unity 3D read siganls from Arduino.
At first, i watched some Youtube videos introducing how to connect Arduino by Unity with some plugins, like the Ardity and Uduino. However, they all failed to work. At last, i learned that they just can be combined directly without any plungins.
Following this tutoril, i can roate a cube in Unity by swinging a knob(B10k) in Arduino.In the Arduino, i just need to print the signal needed. In the Unity, i have to use IO.Ports system first，and then state the same serial port as Arduino.Check this serial port is open, and finally read that signal in the right form. Basically, these are the steps to connect Unity and Arduino. Then i moved to my project. I let the three IR receivers print 1,2 and 3 when they receive the signal. In the Unity, i tried to print the signal to see whether the connection is successful.
Actually, i tried hundreds of time before i made it. The problem is about the way to read serial, and the type of serial. We have to change the form of these according to project we work on. For example, i should use"Readline" to read the serial in the Youtube tutorial i followed at first, but use "ReadByte" in my project.Thanks to Ben, i finally figured out the errors in my codes.