Search Unity

How to access Game World variables in TextMeshPro objects for display

Discussion in 'Scripting' started by ScorpionWasp, Sep 25, 2020.

  1. ScorpionWasp

    ScorpionWasp

    Joined:
    Jun 19, 2020
    Posts:
    19
    I feel this is a really dumb question, but it's giving me grief. I have a main World object that stores all sorts of variables about the game world in its class, that are used in all sorts of routines. And then I have that canvas object with children interface objects, and they have to access those variables for display, without breaking the routines that also need to access them.

    How do I go about accomplishing that, in terms of hierarchy structure and code?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Traditionally you have a script on the UI for a particular UI, and it can be one script or 57,000 little tiny scripts.

    Those scripts are responsible for updating values from a known central data pool to present however is appropriate: eg., display as a number, display as a slider, graph, etc.

    I wrote a general purpose data backing and UI interop package I call Datasacks, and it works like this:

    20180724_datasacks_overview.png

    You can get it here:

    Datasacks is presently hosted at these locations:

    https://bitbucket.org/kurtdekker/datasacks

    https://github.com/kurtdekker/datasacks

    https://gitlab.com/kurtdekker/datasacks

    https://sourceforge.net/projects/datasacks/

    Feel free to use whatever seems of interest to you.