x


How does Javascripts makes use of classes ?

I'm new to Unity and when i create a new C# file at the top there's always:

using UnityEngine; 
using System.Collections;

but for Javascript files there's no classes included in the files and maybe that's why i'm getting the following warnings:

Warning message : Namespace 'System.Collections' is never used (BCW00)
Warning message : Namespace 'UnityEditor' is never used (BCW00)

Must be a very simple tweak but i can't figure it out so help please

more ▼

asked Sep 17 '11 at 07:12 PM

Nu2Unity gravatar image

Nu2Unity
1 1 1 1

(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

First of all in .NET / Mono you can't "include" other classes. "using" is just a shortcut. It tells the compiler when it can't find a certain class in the current namespace to look in those given by the using statement.

You can always write the full classname without the help of any "using"(C#) / "import"(UnityScript).

In UnityScript(Javascript) the compiler includes the UnityEngine namespace by default, so all runtime classes that comes with Unity are available. System.Collections contains some helper classes like List, Hashtable,... If you don't use any of those classes you don't need to include that namespace. However, as i said you can always use the full path to use a class from another namespace.

Instead of including the "System.Collections.Generic" namespace to use the List.<> class you can also write:

var myList : System.Collections.Generic.List.<String>;
myList = new System.Collections.Generic.List.<String>();

using / import are just helpers to shorten the classnames.

Your second warning about "UnityEditor" also tells me that you included the UnityEditor namespace. Keep in mind that the classes defined in UnityEditor are not part of the engine and should only by used in editor-scripts, otherwise you can't build your project.

more ▼

answered Sep 17 '11 at 08:22 PM

Bunny83 gravatar image

Bunny83
45.3k 11 49 207

thank u for ur reply i understand that by default required namespaces would be included but on my pc i'm getting whole host of errors for some reason please go to the following image link:

http://i54.tinypic.com/al3z4m.jpg

please suggest what i should do

Sep 17 '11 at 09:04 PM Nu2Unity

Well, i use exclusively C sharp so i don't get any warnings of this kind. What Unity version are you using? Also i'm don't use MonoDevelop (VisualStudio ftw) but have you tried to reimport those scripts and force a solution sync in Unity so the scripts get recompiled? If you do that you should also delete the solution files before you sync.

Beside that they are just warnings to inform you and not real errors. If you can't get rid of them you should file a bug-report because it's a pain to debug with a bunch of (quite useless) warnings.

Maybe the warnings can be disabled. Usually you can selectively disable warnings.

Sep 17 '11 at 11:32 PM Bunny83

i've tried reimporting the whole project but still the same problem but how do i force a solution sync?

Sep 18 '11 at 01:02 AM Nu2Unity

Just right-click anywhere in the project-panel and select the last item: "Sync MonoDevelop Project"

Sep 18 '11 at 04:17 AM Bunny83

oh! that didn't help either

Sep 18 '11 at 09:31 AM Nu2Unity
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3460
x20

asked: Sep 17 '11 at 07:12 PM

Seen: 2204 times

Last Updated: Dec 25 '12 at 09:49 PM