Forum rules - please read before posting.

Code to show Game version.

Hello everyone,
a simple question for those who chew code.
I would like to insert a menu that reads the version of the game that I set on Unity at Edit > Project Settings > Player.
I did it this way:
-I created a Global Variable with ID 22, called "Version" of type "String", connected to Custom Script and this script has to set the initial value.
-I create a menu called "Version".
-Inside it I create an element called "Label" which will display the version.
This "Label" element is of type Global Variable and refers to the variable "Version".

Now I create a C# script which I call ShowVersion.
Searching online I found that to get the Readonly string from Edit > Project Settings > Player, you have to enter this code:

using UnityEngine;

public class ApplicationVersionExample : MonoBehaviour
{
    // Use this for initialization
    void Start()
    {
        //Ouput the current Application version into the Console
        Debug.Log("Application Version : " + Application.version);
    }
}

And I entered it this way(logically being completely ignorant on the subject I have no idea if I'm even on the right track), and I don't get any errors shown.
So all confident I go to launch but get no string on the label.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using AC;

public class ShowVersion : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        AC.GlobalVariables.SetStringValue(22, Application.version);
    }

    // Update is called once per frame
    void Update()
    {

    }
}

Surely the code is wrong, could you give me a hand on the correct way to write it to assign to the Global Variable "Version" what I wrote in Edit > Project Settings > Player?

Thanks for your help.

Comments

  • If the variable's value is only set once, it needn't have its Link to property set to Custom Script. This option is for when you want to synchronise its value with a variable in another script or asset, so that the two both change together.

    Details on this topic can be found in the Manual's "Variable linking" chapter, but in this case the above script ought to work just by setting the property back to None.

  • Thanks for the reply Chris, I can't test it now, I will in a little while.
    But from the answer you gave me, I understand that the code I wrote is correct.
    That would be a great stroke of luck!

  • No, I can't get it to work.
    I have now set the properties of the Global Variable to none, but when I launch the game, I don't see what I wrote in Edit > Project Settings > Player.
    Going to inspect the variable when the game has started, I see that its value is not updated, it remains empty.

  • solved...
    As usual, I had forgotten to run the script by adding it to the persistent engine.
    Sorry about that.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.