Search Unity

Changing Int order causing it to not work.

Discussion in 'Scripting' started by DarkCSFixer, Jun 25, 2017.

  1. DarkCSFixer

    DarkCSFixer

    Joined:
    Feb 24, 2017
    Posts:
    19
    While working on my clothing store I noticed something really weird.

    Writing the code in this order does NOT work correctly. Only PreviewColor1 registers, PreviewColor2 and PreviewColor3 always come back as 0.

    Code (CSharp):
    1. PreviewColor1 = COLORPants1;
    2. PreviewColor2 = COLORPants2;
    3. PreviewColor3 = COLORPants3;
    4. BARPreviewColor1.value = PreviewColor1;
    5. BARPreviewColor2.value = PreviewColor2;
    6. BARPreviewColor3.value = PreviewColor3;
    While on the other hand this order works perfect.

    Code (CSharp):
    1. PreviewColor1 = COLORPants1;
    2. BARPreviewColor1.value = PreviewColor1;
    3. PreviewColor2 = COLORPants2;
    4. BARPreviewColor2.value = PreviewColor2;
    5. PreviewColor3 = COLORPants3;
    6. BARPreviewColor3.value = PreviewColor3;
    Can someone please explain to me whats going on? I'm so confused.
     
  2. WheresMommy

    WheresMommy

    Joined:
    Oct 4, 2012
    Posts:
    890
    Just a guess, maybe your colorpants2 is not available at that time? Did you try to debug.log just the values instead?
     
  3. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    As this appears to be valid code (without knowing more about it), we cannot really help you to find the issue.

    Either log values until you find the root of the mystery. Or even better, attach the debugger in order to step through your code. You'll be able to see all the current values of the application's state when you hit a break point.
     
  4. DarkCSFixer

    DarkCSFixer

    Joined:
    Feb 24, 2017
    Posts:
    19
    Okay after more testing I figured out the problem. When I changed the value it was grabbing another part of my script which was suppose to active when the value changed. Apparently it was doing this at just right speed to mess up code.