I’m not very good at code so perhaps someone can point me in the right direction as to why this part of the code is not being reached. If I comment all of the update out above it then it does read. So I’m sure I’m buggering up something not being too familiar with it.
try
{
MoveObject(sp.ReadByte());
print(sp.ReadByte());
}
catch (System.Exception) {
}
This is the code with the rest of the Update.
// Update is called once per frame
void Update () {
amountToMove = speed * Time.deltaTime; // New Test For Arduino Move Cube
//print("BytesToRead" +sp.BytesToRead);
message2 = sp.ReadLine();
string message = sp.ReadLine(); //get the message...
if(message == "") return; //if its empty stop right here
// parse the input to a float and normalize it (range 0..1) (we could do this already in the Arduino)
float input = 1 - float.Parse (message) / 100f;
// set the slider to the value
float oldValue = slider.value; // -------- this is new
slider.value = input;
// after the slider is updated, we can check for the other things for example play sounds:
if (source.isPlaying) return; // if we are playing a sound stop here
// else check if we need to play a sound and do it
if (slider.value > 0.9f && oldValue <= 0.9f) // ---------this has changed
source.PlayOneShot (BrightnessAudioClips [Random.Range (0, BrightnessAudioClips.Length)]);
else if (slider.value < 0.15f && oldValue >= 0.15f) //----------this has changed
source.PlayOneShot (DarknessAudioClips [Random.Range (0, DarknessAudioClips.Length)]);
try
{
MoveObject(sp.ReadByte());
print(sp.ReadByte());
}
catch (System.Exception) {
}
}