For example: the user inputs his age as “25” and store it as AGE in the start. In some other scene, i need to show a text which says: "Your age is [AGE] years old. How will i be able to do that in C#. Thank you in advanced!
There are many ways to do this.
You can use a static class.
public static class PlayerSessionData
{
public static int age; // this will be persistant
}
public class PlayerData : MonoBehaviour
{
// then you can map this value anywhere to use it
public int age
{
get { return PlayerSessionData.age; }
set { PlayerSessionData.age = value; }
}
}
Or you can use a static variable in a class
public class PlayerData : MonoBehaviour
{
public static int age;
}
Or you can use PlayerPrefs to store it, this will be available from a session to the next then.
public class PlayerData : MonoBehaviour
{
// then you can map this value anywhere to use it
public int age
{
get { return PlayerPrefs.GetInt("PlayerAge"); }
set { PlayerPrefs.SetInt("PlayerAge", value); }
}
}
Or you can also keep all this in one script, on one object, across loadings with DontDestroyOnLoad, simply disabling display of UI elements when you need.