Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Defective02 · Jan 04, 2015 at 10:38 PM · c#javascriptvariableinspector

Javascript and C#, different behaviour in inspector ?

Hello everybody ^-^ and Happy New Year :D (few days late ^-^')

I've recently changed from javascript to c# and i have a slightly doubt about the inspector behaviour with the last one.

I mean, when i add a class as a variable of another in javascript:

 #pragma strict
 
 public class A extends MonoBehaviour {
     public var pol : int;
     public var b : B;
 }
 
 #pragma strict
 
 public class B {
     public var al : int;
 }

in the inspector i can access the public variables from the second (B) in the object containing the first (A), like this:

alt text

But when i try to do the same in C#:

 using UnityEngine;
 using System.Collections;
 
 public class C : MonoBehaviour {
     public int pol;
     public D d;
 }
 
 using UnityEngine;
 using System.Collections;
 
 public class D  {
     public int al;
 }
 

I can't get the same inspector menu (i get this):

alt text

Unless i use [System.Serializable] in the second :

 using UnityEngine;
 using System.Collections;
 
 [System.Serializable]
 public class D  {
     public int al;
 }

Then i get the same result as in javascript (in the inspector C has the D menu to modify, can't post more images it seems ^-^').

So my question is, am i doing something wrong in C# to have that different behaviour? Is that javascript is already serializable (has something similar to System.Serializable by default in each class already)? Should i change the way of doing it? :o

Thank you in advance ^-^

dibujo.jpg (5.7 kB)
dibujo.jpg (6.0 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Kiwasi · Jan 04, 2015 at 11:06 PM

JavaScript does a lot of things for you in the background. This is why its considered 'easier to learn'. The down side is you are giving up some control. It also requires a fair bit of knowledge to know exactly what is happening behind the code.

C# requires you to do things manually. This means it does what you tell it to, allowing users more control. But it does mean you have to write out more code explicitly.

Declaring variables is another good example. C# will not let you use var at the class scope, you have to define it explicitly with a type. JS lets you use var and the compiler figures out what you were talking about. The compiler can actually mask some errors as it tries to help you. This is one of the key reasons I prefer C#.

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 Defective02 · Jan 15, 2015 at 11:09 AM 0
Share

Need to get used to it then, i guess that i'll have to add that line ^-^ Thank you for the answer :)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Need to use 2 different language scripts. 1 Answer

Access a JavaScript variable from a C# script? 2 Answers

What is this C# code in javascript 0 Answers

Javascript equivalent of an inspector C# public List? 1 Answer

Why is my class hidden in inspector with C# and not JS? 1 Answer


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