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 rednax20 · Dec 02, 2013 at 03:45 AM · objectnewdifferentdeclaration

Declaring a new Object (JS)

the following code does not work

 var myobj =new Object();
 myobj.strength = 15;

i get a long error, starting with "MissingFieldException: System.Object.strength".

I am fairly proficient in my javascript knowledge. this is not the first time something i have typed into the unity editor that would work perfectly in plain javascript has not worked. Often times things have slightly different names, like Math in JS and Mathf in Unityscript.

Am i off my rocker? did i forget what i know about objects? or is this just not mean what i think it means.

any help to point me in the right direction to preforming this correctly is greatly appreciated.

Have a Quishtay™ Day!

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
1
Best Answer

Answer by robertbu · Dec 02, 2013 at 03:51 AM

I believe your first line is creating a Unity Object:

http://docs.unity3d.com/Documentation/ScriptReference/Object.html

Unity objects don't have a 'strength'. Assuming 'Object' is the name of your script/class, try renaming the class to something other than 'Object'. Also note that you don't want to use the 'new' operator if your class is derived from Monobehaviour.

Comment
Add comment · Show 8 · 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 rednax20 · Dec 02, 2013 at 04:05 AM 0
Share

how do i not make it a unity object?

First off i have no idea what a "class" is, i never learned about them, i am trying to achieve this in unity:

http://www.codecademy.com/courses/spencer-sandbox/1/5?curriculum_id=506324b3a7dffd00020bf661

I don't think i want to create a "Unity" Object, i just want an object with variables that i can assign to, so that i can easily organize information.

Is that just not possible in unity?

Sorry I don't understand this very well could you help me understand

avatar image Eric5h5 · Dec 02, 2013 at 04:14 AM 0
Share

Unity does not use web Javascript; don't use any Javascript tutorials. Unityscript is a custom language. It's quite similar to ActionScript3 however. $$anonymous$$ost ActionScript3 code (including classes) can be ported to Unityscript either directly or with some $$anonymous$$or modifications, as long as it doesn't use Flash-specific APIs of course.

avatar image robertbu · Dec 02, 2013 at 04:38 PM 2
Share

I don't write production code in Javascript, so others on the list will be better at the particulars and issues with Javascript classes. Here is a brief example:

Consider a class as a template for an object. You can do something like:

 #pragma strict
  
 public class Stuff {
         public var strength : float;
         public var bullets : int;
         public var grenades : int;
         public var rockets : int;
         public var fuel : float;
 }
 
 function Start () {
     var myStuff = Stuff();
     myStuff.strength = 100.0;
     myStuff.bullets = 50;
     myStuff.grenades = 3;
     myStuff.rockets = 1;
     myStuff.fuel = 1000.0;
     
     Debug.Log(myStuff.strength);
 }
avatar image robertbu · Dec 02, 2013 at 08:35 PM 1
Share

Yes, you can have methods inside classes.

avatar image Eric5h5 · Dec 02, 2013 at 08:45 PM 1
Share

In Unityscript, scripts are automatically classes that inherit $$anonymous$$onoBehaviour. If you've ever created a script then you're using classes.

Show more comments

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

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Verify if a Component is null 3 Answers

How to make an event happen after an object is collided with 2 Answers

Instantiating an object returns null 0 Answers

How do I Adjust The Colour Of My Object By Percentages? 1 Answer

Checking Player's distance to an Object 2 Answers


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