EndState Conditions

This code provides examples of how GameData variables and dictionary values can be used to control content visible at the endScene.

In this example, the values for several key-value pairs are checked, if RobotState and ZombieState are both "companion", then CatState is set to "companion", and MonsterState is set to "subdued", and LucyState is set to "enlightened".

This script is added to an Empty GameObect in the scene. Similar logic can be added to any scene.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class EndSceneConsequences : MonoBehaviour
{
    string displayString;
    string newLine = System.Environment.NewLine;
    [SerializeField]
    Text resultText;

    // Start is called before the first frame update
    void Start()
    {
        UpdateDisplay(); //make sure this is executed before the NCPActivation in build settings
    }

    void UpdateDisplay()
    {
        string zombieState = GameData.instanceRef.GetChoice("ZombieState");
        string robotState = GameData.instanceRef.GetChoice("RobotState");
        
        if( zombieState=="companion" && robotState == "companion")
        {
        displayString = "Congratulations: You are Enlightened." + newLine + "Because you have 2 companions, your beloved cat snowball is safe." + newLine + "Helping others also helped you.";
            GameData.instanceRef.SaveChoice("CatState", "companion");
            GameData.instanceRef.SaveChoice("LucyState", "enlightened");
            GameData.instanceRef.SaveChoice("MonsterState", "subdued");
        }
        else
        {
            displayString = "Oh my, Snowball has been captured by the villian Mr Big, you will need several companions to help rescue snowball";
        }
        resultText.text = displayString;
    }
}

Last updated