The NPCActivation Script Component can be added to any gameObject where the visibility is dependent on a Key,Value pair of data stored in the userChoice dictionary. The key and valid values for visualization are configured in the inspector. In the case of RobotState, the Robot's visibility in the Store, Forrest, and EndScene require that key: RobotState has value: companion. It that key-value pair does not exist in the dictionary, then the gameObject has SetActive( false ).
The image above shows that the key: RobotState must have value of companion.
NPCActivation: For a given key, there can be a list of possible values, such that if any of these values exist in the dictionary for the given key, then the gameObject will be visible in the scene.
This occurs in the BeginScene when the ChoiceButton, with the SaveChoice script attached: as configured below:
Selling the Robot: saves: key: RobotState, value: parts,
We can execute either ActivateNPC( ) or DeactivateNPC( ) using a UI button if we want the robot disappears to disappear when the Button with SaveChoice is Executed
usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassNPCActivation:MonoBehaviour{ [SerializeField]string key; //value required in order to be visible [SerializeField]string[] active_values; //set values that determine visibility within each scene // Start is called before the first frame updatevoidStart() {CheckActiveStatus(); //check curValue stored value to see if it matches any scene set values, so that it is visibl } //call each time gameData playerData is updated //check choiceData dictionary to see if the curValue matches any values for activation of //this gameObject within this scene.publicvoidCheckActiveStatus() {string curValue =GameData.instanceRef.GetChoice(key);bool activate =false; //for key, see if the actual stored value matches any of the listed values //if so, then the gameObject should be activated.for( int i=0; i <active_values.Length; i++) {if (curValue ==active_values[i]) //see if current value matches any required for visibility { activate =true; } }if(activate) {ActivateNPC(); }else {DisableNPC(); } } // Update is called once per framepublicvoidActivateNPC() {this.gameObject.SetActive(true); }publicvoidDisableNPC() {this.gameObject.SetActive(false); }} //end class