-1
\$\begingroup\$

How can I change the script to allow the end user to enter a URL, in the game view themselves, instead of me at the back end?

Here is the Unity script that I am using successfully to allow me add an asset bundle in the scene view at the back end:

using System;
using UnityEngine;
using System.Collections; 

class NonCachingLoadExample : MonoBehaviour 
{
    public string BundleURL;
    public string AssetName;

    IEnumerator Start() 
    {
        // Download the file from the URL. It will not be saved in the Cache
        using (WWW www = new WWW(BundleURL)) 
        {
            yield return www;

            if (www.error != null)
                throw new Exception("WWW download had an error:" + www.error);
             AssetBundle bundle = www.assetBundle;

             if (AssetName == "")
                 Instantiate(bundle.mainAsset);
             else
                 Instantiate(bundle.LoadAsset(AssetName));

             // Unload the AssetBundles compressed contents to conserve memory
             bundle.Unload(false);

        } 
        // memory is freed from the web stream (www.Dispose() gets called implicitly)
    }
}

It should look something like this:

The user should be able to enter the URL at the game screen.

\$\endgroup\$
  • \$\begingroup\$ I want to know what script will allow me to perform this function in unity3d. \$\endgroup\$ – Navid Azhar Sep 16 '16 at 8:20
  • \$\begingroup\$ So you want someone else to do your work for you? \$\endgroup\$ – Tyyppi_77 Sep 16 '16 at 8:21
  • \$\begingroup\$ Please there is no need to be judgemental. My scripting knowledge is limited so I am looking for someone who can help me achive this function and i am willing to pay for their service, if this site is not ment for this type of help then i am sorry for this let me know i will remove my request. \$\endgroup\$ – Navid Azhar Sep 16 '16 at 8:28
  • \$\begingroup\$ Yeah, this site is for Questions and Answers. This is not the site for looking for people who would work for you. See the help center. \$\endgroup\$ – Tyyppi_77 Sep 16 '16 at 8:38
  • 2
    \$\begingroup\$ Just to clarify, youve gone from asking us to create a script in order to allow you to download an external asset, to asking us how to create a simple user-input text box? \$\endgroup\$ – Gnemlock Sep 16 '16 at 9:09
0
\$\begingroup\$

I'm not exactly sure what you're asking, but I'll try anyway

First of all you're gonna have to call Start when you click on the Load button, and as you can't start coroutines from the editor, you're need a wrapper that looks something like this:

public InputField URLField; //For pointing to the inputField

public void StartWrapper() //Add this to the Button's onClick field
 {
     BundleURL = URLField.text; //get url from field
     StartCoroutine(Start());
 }

This gets the text from the InputField you've selected As long as you remember to select the InputField in the Editor!

Lastly add this to the top of the file to be able to refer to UI elements like the InputField:

 using UnityEngine.UI;

Since you already use BundleURL in you Start coroutine, no editing is necessary there.

\$\endgroup\$
  • \$\begingroup\$ @NavidAzhar Did it work for you? \$\endgroup\$ – ZEKE Sep 18 '16 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.