Determine Which Switch Case Was Called Last C#
I'm using a series of switch cases for voice response request like this:
 case "WhatDoYouThinkOfThisTown":
                 //Check if it Is Michael And That Shut Up Mode Is OFF
                 if ((KITTmodesObject.isMichael == true) && (KITTmodesObject.KITT_isSpeaking == false) && (KITTmodesObject.ShutUpMode == false)) {
                     Debug.Log ("Michael Asked --- What Do You Think Of This Town?");
                     KITTvoiceBox.WhatDoYouThinkOfThisTownResp ();
                 }
                 break;
 
               Is there a way to determine in a public variable witch case was called last? Perhaps something like: public "___" lastQorA; The "blank" being I'm not really sure how to access this part of the Switch case in a public variable I can then access in other switch cases:
case "WhatDoYouThinkOfThisTown": And then use that is another switch case something like:
 if (lastQorA.name == "WhatDoYouThinkOThisTown"){
 Do Something
 }
 
              Answer by joshuauhler · Nov 17, 2016 at 05:56 PM
Your case seems to be a string so put this at the top of your class file:
 public String lastQorA;
 
               After your case line:
 lastQorA = [your switch variable here];
 
              Thanks @joshuauhler After a bit of experimenting I ended up doing this:
 public string lastQorA;
 
                  And then in my case doing this:
 case "CanYou$$anonymous$$eepAsecret":
                 //Check if it Is $$anonymous$$ichael And That Shut Up $$anonymous$$ode Is OFF
                 //Lets Say you Already Asked $$anonymous$$.I.T.T. This
                 //$$anonymous$$ood Is Good
                 if ($$anonymous$$ITTmodesObject.is$$anonymous$$ichael == true && $$anonymous$$ITTmodesObject.$$anonymous$$oodIsGood == true && $$anonymous$$ITTmodesObject.Surveilance$$anonymous$$odeActive == false
                     && $$anonymous$$ITTmodesObject.$$anonymous$$ITT_isSpeaking == false && $$anonymous$$ITTmodesObject.ShutUp$$anonymous$$ode == false) {
                     if (lastQorA == "CanYou$$anonymous$$eepAsecret"){
                         $$anonymous$$ITTvoiceBox.YouHadAlreadyAskedThatResp ();
                 } else if (($$anonymous$$ITTmodesObject.is$$anonymous$$ichael == true) && ($$anonymous$$ITTmodesObject.$$anonymous$$ITT_isSpeaking == false) && ($$anonymous$$ITTmodesObject.ShutUp$$anonymous$$ode == false)) {
                         Debug.Log ("$$anonymous$$ichael Asked --- Can You $$anonymous$$eep A Secret Pal?");
                         $$anonymous$$ITTvoiceBox.CanYou$$anonymous$$eepAsecretResp ();
                         //Positive So Add "2" points To The $$anonymous$$ood Level
                         $$anonymous$$ITTmodesObject.$$anonymous$$ITT_$$anonymous$$oodLevel += 2;
                         lastQorA = "CanYou$$anonymous$$eepAsecret";
                     }
                 }
                 break;
 
                  Not sure how robust it is but it seems to work, your method might be better???
Your answer
 
             Follow this Question
Related Questions
How to Reference Other Scripts' Variables in C# 1 Answer
Can I access a Switch case from a Coroutine? 0 Answers
Issues With Touch Rotation code 0 Answers
public vs private array in classes 0 Answers
switch case statment 0 Answers