Scriptable Objects Quick Demo in Unity Game Engine


PlayerData.cs
using UnityEngine;

[CreateAssetMenu(menuName ="Player Data", fileName ="New Player Data")]
public class PlayerData : ScriptableObject
{
    public string playerName;
    public string playerClass;
    public Color playerColor;
}

PlayerDisplay.cs
using UnityEngine;

public class PlayerDisplay : MonoBehaviour
{
    public PlayerData playerData;

    void Start()
    {
        transform.GetChild(0).GetComponent<TextMesh>().text = $"Name : {playerData.playerName}";
        transform.GetChild(1).GetComponent<TextMesh>().text = $"Class : {playerData.playerClass}";
        gameObject.GetComponent<Renderer>().material.color = playerData.playerColor;
    }
}