Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by AlphaGarg8447 · Sep 22, 2015 at 08:58 PM · animationjavascriptvariablevariables

Help with variables

I want to add three variables together, but I am having trouble. Like this:

"variable12 = variable1 + variable2;"

But, of course, JS doens't work like that and I should've used C#. Please, I need this for tomorrow on my schools science fair, I'm making a quiz.

Comment
Add comment · Show 2
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 yoda12 · Sep 22, 2015 at 10:27 PM 0
Share
 var a = 1;
 var b = 2;
 var c  = 3;
 
 a = a + b + c;

Does that help?

Or do you want to add three strings?

avatar image Maruder · Sep 22, 2015 at 11:05 PM 0
Share

@$$anonymous$$arcos42563

where are you calculating these variables at? In Start(), Awake(), or Update() function?

1 Reply

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

Answer by spinnerbox · Sep 23, 2015 at 03:30 PM

So to make things clear, JavaScript(UnityScript) in Unity is not true JavaScript it is C# that looks like JavaScript :) I don't have large experience in UnityScript(JavaScript in Unity) but this should be very easy to answer:

  1. Create new Unity Project.

  2. Create new empty game object.

  3. Call it JSTest.

  4. Press "Add component" button in the inspector and then select "New Script". Choose JavaScript format.

  5. type this code below pragma inside:

code:

 public var a = 1;
 public var b = 2;
 public var c = 3;
 
 function Start () {
  
      a += (b + c);
      Debug.Log("a = " + a);
 }
 
 function Update () {
 
 }

So each game object inherits from MonoBehaviour. In JavaScript you type #pragma strict but the interpreter knows which namspaces to import so you don't have to worry about that. Each game object has several default functions which get executed when the object is instantiated and while the game is running. Those can be Awake, Start, Update, FixedUpdate, OnGUI etc... To initialize in first frame use Awake(). To intialize when the object is instantiated use Start(). The public keyword makes the variables visible in the inspector like so:

js-test


js-test.png (63.1 kB)
Comment
Add comment · 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

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

37 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 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 avatar image avatar image avatar image

Related Questions

assign a new value to a variable 0 Answers

How to get all the variables in a folder. C# 0 Answers

Interchangeable animations in a script? 0 Answers

NullReferenceException: Object reference not set to an instance of an object 1 Answer

I want my character to enter and exit car with animation 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