- Home /
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
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 ?
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).
If thus isn't clear, you'll need to post code that you're having the problem with.
Answer by Eric5h5 · Jun 21, 2011 at 11:51 PM
http://unity3d.com/support/documentation/ScriptReference/index.Script_compilation_28Advanced29.html (Specifically part 4.)
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.