- Home /
How to add item to Script Written in C# ?
Hello again, I wrote 2 script sheets. One of them is C# and other is JS.
So, I've got an array list in C#, I want to add new items with my javascript. But MonoDevelop can't shows the script in code suggestions :/
As you can see at the picture below ;
There's ArrayListForDucks is opened at tab, but doesn't seen by Mono ? So what can i do ? All Variables are Static.
Answer by ArkaneX · Sep 03, 2013 at 02:59 PM
The problem is that C# project and JS project are separate and types in one of them doesn't know about types in second. You can trick this behavior by putting ArrayListForDucks.cs into Assets\\Plugins folder (see this question for explanation).
But if you don't have to use different languages, then just stick to either C# or JS.
Your answer looks right but somehow wrongly said. Projects are not really separate, they use different compilers. So it is possible to have one class seeing the other but it won't do the other way. You cannot have two ways communication between two classes and the way to communicate is as you claim, putting the one to be looked at in the Plugins or StandardAsset folders.
By 'separate', I mean they don't reference each other. If you drop your script to the Plugins folder, a third project is created and its reference is added to both C# and JS projects.
I don't use $$anonymous$$onoDevelop, so maybe it behaves differently, but in Visual Studio I can't see standard JS classes in C# as well as C# classes in JS.
I don't know how to use "List" method at JS, Sorry I'm 14 years old :/ At my other questions they told if you want to use something with arrays use List method with C#, So i wrote this but I'dont know how to write my other code at C# :/
In order to use generic List in JS, you have to import proper namespace:
import System.Collections.Generic;
and then, to create List of string elements, you can use:
var list : List.<String> = new List.<String>();
list.Add("aaa");
list.Add("bbb");
for(var x : String in list)
{
print(x);
}
You can read more about generic lists here. Scroll to bottom of the page to see examples. JavaScript (UnityScript) notation is a bit different, because you have to use additional dot character before type info (like in my example).
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
How To Get A Reference To All Nearby GameObjects? 1 Answer
How do i convert this code snippet to a list? 1 Answer
[C#]Inventory script help. 3 Answers
UnityScript for unique simpleJSON lists 0 Answers