Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 oussema · Jun 21, 2011 at 11:39 PM · getcomponentc#-and-js

C# GetComponent

Hello Everybody, I wanted to ask how can I access a variable in a Javascript file from a C# file ... thanks in advance

Comment
Add comment · Show 1
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 oussema · Jun 22, 2011 at 07:26 AM 0
Share

This is the code I wrote in C#:

using UnityEngine; using System.Collections; using System.IO; using System; using System.Xml; using System.Diagnostics;

public class CreationFichierX$$anonymous$$L: $$anonymous$$onoBehaviour { public Temps Passage; // Use this for initialization void Start () {

      }
      
     void Update(){
         Passage = GetComponent("Temps") as Temps;
         if(Passage.PasserStage==true){
         XmlWriterSettings FichierX$$anonymous$$L = new XmlWriterSettings ();
         FichierX$$anonymous$$L.Indent = true;
         using (XmlWriter writer = XmlWriter.Create ("Jeu.xml",FichierX$$anonymous$$L)) {
         writer.WriteStartDocument();
         writer.WriteStartElement ("Jeu");
         writer.WriteElementString ("Valeur","2"); 
         writer.WriteElementString ("Bonus","0"); 
         writer.WriteElementString ("Sanction","0"); 
         writer.WriteEndElement ();            
         writer.Close ();
         }
         FileStream Fichier = new FileStream ("Jeu.xml", File$$anonymous$$ode.Append, FileAccess.Write, FileShare.Read);
         Process.Start("$$anonymous$$ap.exe");
     }
         }
      
      
  }

the probleme is that he don't recognize the JS script "Temps"; the type or namespace name "Temps" could not be found.Are you missing a using directive or an assembly reference ?

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Waz · Jun 21, 2011 at 11:49 PM

Nothing special. Regardless of language, components are compiled down to the same thing, so it's no longer JS by the time your C# is accessing it (and neither is your C# still C# for that matter).

Comment
Add comment · Show 1 · 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 Waz · Jun 21, 2011 at 11:51 PM 0
Share

If thus isn't clear, you'll need to post code that you're having the problem with.

avatar image
0

Answer by Eric5h5 · Jun 21, 2011 at 11:51 PM

http://unity3d.com/support/documentation/ScriptReference/index.Script_compilation_28Advanced29.html (Specifically part 4.)

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 GuyTidhar · Jun 22, 2011 at 08:50 AM

If you javascript will be under a "Plugin" folder and your C# won't be, the JS will be compiled before the C# and the JS will recognize the Temps object.

Comment
Add comment · Show 1 · 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 GuyTidhar · Jun 22, 2011 at 08:51 AM 0
Share

correction "Plugins" (with an S)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Unknown identifier when turning off SSAO through a JS script 1 Answer

passing variable from javascript to C# 1 Answer

trying to set a javascript variable from c sharp 1 Answer

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

Make C# Class Globally Available on JavaScript 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