Question by
KnightRiderGuy · Jan 02, 2016 at 06:23 PM ·
c#scripting problemscripting beginnercodepage
Can Someone Explain Why Message does not show Anything In Inspector
OK This is confusing enough at the bets of time but can some please explain why Message3 does not show anything in the inspector.
How the heck does Unity know the difference between the different message , message2, message3 anyways. I don't get it.
public string message2;
public string message3; //Not sure why this was here as it does not seem to make a difference??
public string message4;
//Button States
bool button01State = false;
float timePassed = 0.0f;
// Use this for initialization
void Start () {
StartCoroutine(OpenConnection());
lightSlider = GetComponent<Slider> ();
if(slider == null) slider = GetComponent<Slider>(); // search slider in this object if its not set in unity inspector
if(source == null) source = GetComponent<AudioSource>(); // search audiosource in this object if its not set in unity inspector
}
// Update is called once per frame
void Update () {
try
{
string message3 = sp.ReadLine(); //get the message...
if(message3 == "") return; //if its empty stop right here
print(message3);
DirectionArrow (message3.Trim());
}
catch (System.Exception ex) {
//print (ex.Message);
return;
}
//HOW DO I GET THE TEMPERATURE DATA FROM THE SERIAL AND DISPLAY IT ON THIS UI TEXT?
//Without is conflicting with the LDR data
//Also HOW the heck does UNITY know to read out the LDR information as Message2?
//when message3 (Buttons inputs) is working but not displaying anything in the inspector?
TemperatureText.text = TempSensorData.ToString ();
//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;
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)]);
}
Comment