- Home /
How to convert a string to a type WWW
So I am stuck at the moment. Need to be able to get textures from online, but I want the player to be able to choose the texture. It is working fine when I put the url into the code, but when I try to get a value from an InputField it gives me an error.
The code that works:
WWW www = new WWW("http://www.textures.com/system/categories/65/frontend-large.jpg");
yield return www;
texture = www.texture;
The code that doesn't work:
WWW www = new WWW(textureInputField.text);
yield return www;
texture = www.texture;
It just keeps telling me the same thing... that my string doesn't match the type of variable it was looking for.
(or more explicitly)
"NullReferenceException: Object reference not set to an instance of an object UIScript.ApplyTexture () (at Assets/UIScript.cs:63)"
I know what the problem is, but I was wondering if there was a solution that I am oblivious to at the moment.
I don't think that is what the error means. Your textureInputField variable is likely null when these particular lines are called. This is easily verified with a debugger. Is it not yet assigned? Has it never been assigned? That's hard to say without a bit more information.