Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Arutha · Jan 20, 2013 at 11:24 AM · wwwdatabase

Connection with a MySQL Database

Hello,I'm new to Unity and I have the following problems in my JS Code :

I have the following Exception when I run my Project :

"UnityException: WWW is not ready downloading yet UnityEngine.WWW.get_text () (at C:/BuildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/Editor/Utils.cs:87) bdd_description..ctor () (at Assets/Standard Assets/bdd_description.js:6)"

ArgumentException: InitWWW can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function. UnityEngine.WWW..ctor (System.String url) (at C:/BuildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/Editor/Utils.cs:28) bdd_description..ctor () (at Assets/bdd_description.js:7)

Here is the code :

var afficher : boolean = false;

var res= "http://localhost/searchname.php";

var www : WWW = new WWW (res);

yield www;

var description=www.text;

If somebody can help me it will be great !

function OnGUI() {

 //style label
 var bulle=new GUIStyle();
 bulle.normal.textColor=Color.red;
 bulle.fontSize=15;
 bulle.fontStyle= FontStyle.Bold;
 bulle.border.right=1;
 
 var bulle2=new GUIStyle();
 bulle2.normal.textColor=Color.red;
 bulle2.fontSize=15;
 bulle2.fontStyle= FontStyle.Italic;
 bulle2.border.right=1;
 
 var info= "Immeuble" ;
 var e : Event = Event.current;
 
 if (afficher == true) {
     GUI.Label (Rect (e.mousePosition.x+20, e.mousePosition.y+20, 300, 100), info, bulle );
     GUI.Label (Rect (e.mousePosition.x+40, e.mousePosition.y+40, 300, 100), description, bulle2 );
     }

}

function OnMouseOver () { afficher = true; }

function OnMouseExit () { afficher = false; }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by kat0r · Jan 20, 2013 at 01:17 PM

You do exactly what the compiler tells you:

InitWWW can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.

Move

 var res= "http://localhost/searchname.php";
 var www : WWW = new WWW (res);
 yield www;
 var description=www.text;

To the Awake()or Start() function.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Arutha · Jan 20, 2013 at 02:37 PM

Thank you very much it seems too work like that :

 function Start() {

 var res= "http://localhost/searchname.php";

 var description=WWW(res).text;

 yield description;
 }
 var afficher : boolean = false;
 
 function OnGUI() {
         
     //style label
     var bulle=new GUIStyle();
     bulle.normal.textColor=Color.red;
     bulle.fontSize=15;
     bulle.fontStyle= FontStyle.Bold;
     bulle.border.right=1;
     
     var bulle2=new GUIStyle();
     bulle2.normal.textColor=Color.red;
     bulle2.fontSize=15;
     bulle2.fontStyle= FontStyle.Italic;
     bulle2.border.right=1;
     
     var info= "Immeuble" ;
     var e : Event = Event.current;
     
     if (afficher == true) {
         GUI.Label (Rect (e.mousePosition.x+20, e.mousePosition.y+20, 300, 100), info, bulle );
         GUI.Label (Rect (e.mousePosition.x+40, e.mousePosition.y+40, 300, 100), description, bulle2 );
         }
 }
 
 function OnMouseOver () {
 afficher = true;
 }
 
 function OnMouseExit () {
 afficher = false;
 }

But I've another problem now : how to use my variable "description" (in my function Start()) in my OnGui() function? A little help would be great ! Sorry for the newbies questions ^^

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to get specific data from CURL in unity 0 Answers

Upload audio file into mysql database 0 Answers

WWW doesn't work on localhost eventhough crossdomain.xml exists 1 Answer

WWW does not work on localhost 0 Answers

loading from disk, saving to database 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges