why script work on PC but On android no ......load text php

hello why my scrip not load text on android pls help me here is script :

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

public class StavZapasov : MonoBehaviour
{
    public string readText;

    public string getURL = "http://myweb/LoadText.php";

    public string[] zapasy;

    public Text[] StavZapasovText;






   private void Start()
    {
        StartCoroutine(GetTheText());

      
    }

    // Update is called once per frame
    IEnumerator GetTheText()
    {
        string URL = getURL;
        WWW www = new WWW(URL);
        yield return www;
        readText = www.text;
        for (int a = 0; a < 2; a++)
        {
            zapasy = readText.Split(System.Environment.NewLine[a]);
        }

        for (int i = 0; i < zapasy.Length; i++)
        {
            StavZapasovText[i].text = zapasy[i];
        }
      }
  }

How to report problems productively in the Unity3D forums:

http://plbm.com/?p=220

Help us to help you.

<?php
  header("Access-Control-Allow-Origin: *");
?>

That line should be at the top of your PHP file or you may run into CORS-related exceptions / nothing will load. Do make sure that’s what you want (allowing access to it from anywhere) and that you understand the implications etc.

Make sure the url is https (secure)
It is not allowed on Android to download cleartext via http (unsecure)

also WWW is deprecated by a long time.
UnityWebRequest is the replacement of WWW. Under the hood of WWW it already has been converted to UnityWebRequest.

1 Like

not works :frowning: but thanks your reply

on android work the same script but not have split line here is script

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

public class ReadText : MonoBehaviour
{
    public Text readText;
  
   public string getURL = "http://myweb/LoadText.php";

  








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

    // Update is called once per frame
    IEnumerator GetTheText()
    {
        string URL = getURL;
        WWW www = new WWW(URL);
        yield return www;
        readText.text = www.text;
    }
    
}

Still the url is “http://myweb/LoadText.php”
It should be using https:// due to Android not allowing cleartext over http.
http:// is unsecure and had been disabled by default since Android… 6 or 7 somewhere?

for https traffic you require a certificate. The how to’s of setting that up is not my expertise.

I think unity has/had an option somewhere in the build settings of android to enable insecure traffic over http
But I’m not on my pc right now so can’t check.

hello i have android 10 and http: //myweb/LoadText.php“ works cleartext loaded but lines not i think that error is here

readText Work it on mobile !!!

for (int a = 0; a < 2; a++)
        {
            zapasy = readText.Split(System.Environment.NewLine[a]);
        }
        for (int i = 0; i < zapasy.Length; i++)
        {
            StavZapasovText[i].text = zapasy[i];
        }

unity write error if a > 2

IndexOutOfRangeException: Index was outside the bounds of the array.
StavZapasov+d__5.MoveNext () (at Assets/Uvod/StavZapasov.cs:40)

I use UnityWebRequest for insecure traffic over HTTP for WebGL, Windows 7 and Android 6 and have had no issues except for consideration of CORS policy / what I’ve mentioned earlier in the thread. A similar .htaccess is required with Addressables for remote catalogs/bundles, which I’m including in this thread for anyone else wondering why something is working fine with WAMP but not a live server (do understand what it does before you just copy/paste it though). This goes in the same folder as the Addressables catalog you want to load with LoadContentCatalogAsync, in a file called “.htaccess”:

<IfModule mod_headers.c>
  Header set Access-Control-Allow-Origin "*"
</IfModule>

Note for WebGL, the usual browser restriction applies of pages loaded via HTTPS needing to load subsequent content over HTTPS as well. The browser can’t show people the little lock icon unless all content is being loaded securely.

but i have a problem IndexOutOfRangeException: Index was outside the bounds of the array.

my script load text but not set text on Text.text …readText load data text

Here are some notes on IndexOutOfRangeException and ArgumentOutOfRangeException:

http://plbm.com/?p=236

thank you but this didn’t help me

pls help me whosoever :frowning: is it last script from my application

IndexOutOfRangeException: Index was outside the bounds of the array.
StavZapasov+d__4.MoveNext () (at Assets/Uvod/StavZapasov.cs:34)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Scripting/Coroutines.cs:17)

What output did you see when you compared the indexing value (i) with the length (or count) of the collection?

NOBODY here can answer that. Only you can answer that.

sorry not know what your think … i count is 27 …sorry me english its bad :frowning: