- Home /
Acces C# via Unityscript
Hello, Is it possible to access a variable and change it if it's part of a C# script and Im using Unityscript.
For example. This is the c# script :
public string stringy = "Stringy string";
That's stored in scriptyscript.cs
Can I access it from an unityscript ?
Example :
var varyvar : scriptyscript;
function Start ()
{
varyvar = GameObject.Find("Player").GetComponent(ScriptScript);
}
function func()
{
varyvar.stringy = "Yey, it works"
}
This is the unityscript.js file. It's just an example ,sorry if I wasn't clear enough.
Thank you.
Answer by Kiwasi · Aug 07, 2014 at 06:27 PM
Yes. Check out the docs here.
Note that while it can be done, most people on UA generally recommend against it. Ultimately its a pain to do. Tends to be easier if all scripts are in the same language.
Guys I fixed it.
What I did was I just created a new folder named Plugins and put the scripts in there. That way unity checks them first. Then I used a simple unityscript to access the variables.
Thank you all for trying to help me!
Answer by Foose · Aug 07, 2014 at 06:26 PM
i really dont understand what you are trying there. u can code in js, c# and boo with unity. doesnt matter. So basically u can make one script out of them when u change the unityscript file to cs.
Edit: If you really want to keep the two scripts seperate, I can give you an example how it will work in c# but no clue how it is in js.
Attach the script with the string to a gameobject. Now in your unityscript reference to this script by calling
ScriptyScript str = GameObject.Find("[name of the go the script is attached to]").GetComponent<ScriptyScript>();
str.stringy //is the command you will be using in your unity script to get the stringy variable of the other script)
Actually it does matter. Scripts in different languages can't access each other without some special trickery.
actually downvoting me because you cannot read, isnt cool you know?. I simply said that there is no difference between a c# script and a unityscript because in unity u can progamm in c+ too and unityscript doesnt automatically mean js.
He didn't downvote you 4 times, that's an absolute dead cert. (I didn't downvote you at all).
Save your $$anonymous$$arma, delete the answer.
Downvoting because you're talking utter nonsense...
"There's no difference between a c# script and a unity script"
"In unity you can program$$anonymous$$g in c+ too"
"Unityscript doesn't automatically mean js"
Wrong, wrong, and er, wrong :)
Im actualy trying to access a c# script via unityscript but it's giving me this error :
BCE0005: $$anonymous$$ identifier: 'NA$$anonymous$$EOFTHESCRIPT'.
Long time ago someone told me it doesn't work but then I saw a lot of people actually do it by putting both scripts in the same folder but...it's not working for me.
Your answer
Follow this Question
Related Questions
Trigger player movement on touch 1 Answer
Hide the ImageTraget in Real world 0 Answers
how to acess Static variable in other scripts without extended functions? 2 Answers
Multiple Cars not working 1 Answer