Search Unity

[C#] Character resizing system help.

Discussion in 'Scripting' started by IAmZeph, Feb 6, 2015.

  1. IAmZeph

    IAmZeph

    Joined:
    Feb 5, 2015
    Posts:
    7
    Hello!
    I have a resizeable cube as my character. It has three possible sizes. Normal, small and big. Everything works wonderful. There is just one mistake that buggers me. Why is it that when I go from big down a level it goes to small but not normal? I really need help with it. It's so annoying. Can anybody please say how I need to modify my code to do that?

    Here's what I already have: http://pastebin.com/mSkPRZe8

    - Daniel :)
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Step through this function like a computer program:
    Line 29: "Left bracket was pressed, and isEnabled and isBig are both true, better go into this function. Now I'll set isNormal to true and isBig to false."
    ....and then it continues.
    Line 34: "Left bracket was pressed and isEnabled is true, and isNormal is true. Better run these lines now."

    Easiest fix: make the second 'if' on each of those into an 'else if'.

    Better fix: use an integer to track the size (such as 0,1,2) and add and subtract to it instead of a field of booleans (which, I guarantee you, you are going to break the instant you change any part of this function - running through a checklist of booleans is just not something humans are good at.)