コード例 #1
0
    // Start is called before the first frame update
    void Start()
    {
        textObject = new GameObject();
        textObject.transform.parent   = gameObject.transform;
        textObject.transform.position = gameObject.transform.position;
        textObject.transform.Translate(new Vector3(0f, downDistance, 0f));
        textObject.transform.Rotate(90f, 0f, 180f);
        textMesh = textObject.AddComponent <TextMesh>();

        ObjectActivator objectActivator = gameObject.GetComponent <ObjectActivator>();

        if (objectActivator == null)
        {
            Debug.LogWarning("ObjectActivator is not assigned on object " + gameObject.name);
        }
        else
        {
            int planetNumber = objectActivator.GetPlanetNumber();
            //Load user progress
            string userProgressLoad = PlayerPrefs.GetString("planetProgress" + planetNumber.ToString());
            if (userProgressLoad == "")
            {
                userProgressLoad = "0000";
            }
            userProgress = SetProgressToUserProgressComponent(userProgressLoad);
        }

        //textMesh settings
        textMesh.text          = userProgress;
        textMesh.anchor        = TextAnchor.MiddleCenter;
        textMesh.characterSize = 0.2f;
        textMesh.fontSize      = 18;
        textMesh.color         = Color.green;

        if (userProgress == "")
        {
            Debug.LogWarning("There is no user progress on object " + gameObject.name);
        }
        if (cameraTransform == null)
        {
            Debug.LogWarning("Camera Transform is not assigned to camera object on object " + gameObject.name);
            textObject.SetActive(false);
        }
    }