• 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
1
Question by user-710 (google) · Feb 27, 2010 at 04:46 PM · compiling

I need to call a C# function from Javascript...

I need to write and read config from a external file, the problem is... The function that write changes in the file is written (evidently) in C#, but the GUI script that calls the C# function is written in Js... If I call it like a Js function not works...

c# function is here: (Writer.cs)

 using UnityEngine;
 using System.Collections;
 using System;
 using System.IO;
 
 public class Writer : MonoBehaviour {
 
     private FileInfo theSourceFile = null;
     private StreamWriter writer = null;
     private string sPath = System.Environment.GetEnvironmentVariable("HOMEDRIVE") 
     + System.Environment.GetEnvironmentVariable("HOMEPATH");
     
     // Function that saves the settings in the config file...
     public void write (int resWidth, int resHeight, int Quality) {
     
         if (Application.platform != RuntimePlatform.OSXWebPlayer &&
             Application.platform != RuntimePlatform.WindowsWebPlayer){
     
             if (File.Exists(sPath + "/VHconfig.txt")){
                 Debug.Log("Configuration file found in " + sPath + "/VHconfig.txt" + ". Deleting...");
                 File.Delete(sPath + "/VHconfig.txt");               
             }
         
             theSourceFile = new FileInfo (sPath + "/VHconfig.txt");
             writer = theSourceFile.CreateText();
         
             writer.WriteLine(resWidth);
             writer.WriteLine(resHeight);
             writer.WriteLine(Quality);
         
             writer.Close();
         }
     }
 }

Is called from Js here:

 Writer.write(changedResWidth, changedResHeight, changedQuality);


Any way to call it from Js??

Thanks a lot.

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
8
Best Answer

Answer by Murcho · Feb 27, 2010 at 10:55 PM

JS files are compiled before C# files, so I'm going to make the assumption that you are getting a warning something to the effect "Script doesn't exist" seeing as you haven't provided the exact problem here. The way you're calling it should be right.

To get the C# script compiled before the JS script, place the C# script into the Standard Assets folder. Scripts inside this folder are compiled before scripts in any other folders you make, with the except of a few other special folders. You can find the full compilation order information here.

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 hasCode · Jun 11, 2014 at 08:46 PM 1
Share

http://docs.unity3d.com/$$anonymous$$anual/ScriptCompileOrderFolders.html

avatar image shuvos3 · Apr 07, 2017 at 09:56 AM 0
Share

Thanks. It works

avatar image
0

Answer by Viper5502 · Mar 20, 2014 at 03:37 AM

https://docs.unity3d.com/Documentation/Manual/ScriptCompileOrderFolders.html

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

The type or namespace 'var' could not be found (in C#) 7 Answers

Problem adding script to GUI Texture 1 Answer

Using Pragma to slit app in two 1 Answer

enable multidex for android build 2 Answers

Can I control when unity compiles scripts? 1 Answer


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