-2

enter image description hereI'm new to unity, so any help is greatly appreciated and sorry if the question is a little odd. Anyways, I'm writing a script to check the internet connection and if everything is ok, the player can move to the next scene, if not the access is declined. The script works but only for Legacy Texts, I forgot im using textmesh Pro texts and i cant attach those gameObjects to the script. Does anyone know what i have to change so i can do the exact same thing with my script but with TextMesh Pro texts and not legacy?

Here the script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;

public class CheckInternet : MonoBehaviour
{
    [SerializeField] Text loadingText;
    [SerializeField] Text connectionErrorText;
    [SerializeField] Button tryAgainButton;
    [SerializeField] Button playButton;

    void Start()
    {
        StartCoroutine(CheckInternetConnection());
    }

    IEnumerator CheckInternetConnection()
    {
        UnityWebRequest request = new UnityWebRequest("http://google.com");
        yield return request.SendWebRequest();

        if(request.error != null)
        {
            loadingText.gameObject.SetActive(false);
            connectionErrorText.gameObject.SetActive(true);
            tryAgainButton.gameObject.SetActive(true);


        }

        else
        {
            loadingText.gameObject.SetActive(false);
            playButton.gameObject.SetActive(true);

        }
     }

     public void TryAgain()
     {
        SceneManager.LoadScene(SceneManager.GetActiveScene().name);
     }

     public void Play(int sceneID)
     {
          SceneManager.LoadScene(sceneID);
     }
 }

I couldnt find a solution on my own

derHugo
  • 83,094
  • 9
  • 75
  • 115
Davinci
  • 1
  • 2

1 Answers1

1

For this part of your code [SerializeField] Text loadingText;[SerializeField] Text connectionErrorText;

It is using the legacy text component. To change it to TextMeshPro component, you would have to first add the namespace using TMPro; at the top of your script. Then declaring TextMeshProUGUI instead of Text

You should be able to attach your tmp objects to the script after that.