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 /
avatar image
0
Question by aLucidWorld · May 27, 2010 at 06:32 PM · cs0103c#-and-js

trying to set a javascript variable from c sharp

I am using C Sharp to connect to a Smartfox Server and pull data from a mysql database. When the data is returned (the users display name) I want to set this information to the variable declared in the javascript file.

public void OnExtensionResponse(object data, string type) {
    if(type == "xml") {
        SFSObject dataObject = (SFSObject)data; 
        switch ( dataObject.GetString("_cmd") ) { 
            case "logOK": 
                GameObject.Find("LoginCreds").GetComponent(UserInformation).user_display_name = dataObject.GetString("user_display_name");
                break; 
            case "logKO": 
                loginErrorMessage = dataObject.GetString("err"); 
                break; 
         }
    }
}

Everything is working perfectly with the exception of the 'GameObject.Find... line. I get the following errors -

Assets/Game/Scripts/C Sharp/LoginGUI.cs(99,84): error CS0103: The name `UserInformation' does not exist in the current context

Assets/Game/Scripts/C Sharp/LoginGUI.cs(95,25): error CS0163: Control cannot fall through from one case label to another

Is it even possible to do this? Or should I just accept the fact that I'm going to have to walk away from Javascript and program the entire system in C Sharp?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Cyclops · May 27, 2010 at 08:21 PM

You can call one language from another - but they have to be compiled in the right order for access. See Accessing Javascript from C# for more details.

(Despite the name of the Question, it explains compilation order, and so applies to calling either language from the other.)

Comment
Add comment · Show 2 · 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 aLucidWorld · May 28, 2010 at 12:44 AM 0
Share

So grateful for this link!!!!! I'm using Javascript to access C# and I've got it working great. For those who come across this looking for the same answer, here's how I did it :

I moved all my C# scripts to a subfolder of "Standard Assets". I then created another root level folder called "Game" and put my javascripts in there.. "Standard Assets" folder gets loaded first, so this works.. you can even set the variables!! Thanks again Cyclops!

avatar image ben · Mar 14, 2011 at 06:09 AM 0
Share

send me wt u have did, step by step what we want to declare and use in .js and c#.....i have done it ,but shows some error

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

No one has followed this question yet.

Related Questions

passing variable from javascript to C# 1 Answer

Accessing JavaScript variable from C# and vice versa. 3 Answers

C# GetComponent 3 Answers

Make C# Class Globally Available on JavaScript 0 Answers

iOS / dynamic typing issue: not a member of 'UnityEngine.Component' 2 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