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 vbleyden · Apr 08, 2014 at 04:16 PM · javascriptfunctionsimplebasicwiki

Help with Functions

Hi, I am new to using unity but i have a good grasp on it.

The one thing that slips me up in javascript is the simplest thing it seems, I don't understand the Function Update and Function Start and how / when to use them. Could someone please explain this to me?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by KiraSensei · Apr 08, 2014 at 04:19 PM

Have a look at the doc :

  • HERE for the Update method

  • HERE for the Start method

If this is not enough, you can find some links like this one to complete the doc.

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

Answer by Stormy102 · Apr 08, 2014 at 04:48 PM

function Update() {

}

This is called every frame. Basically, your screen is flickering so fast that the human eye can't see it. A typical computer does sixty frames per second. Anything in function Update() is executed every frame.

function Start(){

}

When your game is started, the code in this is executed first. So, if you want to instantiate a Prefab when the game is started, you would put it in function Start()

Hope this helps!

Stormy102

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 KiraSensei · Apr 08, 2014 at 05:27 PM 0
Share

Not really : the Start function is called when the script containing it is instantiated, so not necessarily at game start.

avatar image
0

Answer by ypsilon · Apr 08, 2014 at 04:47 PM

Update

lmost every game that you'll ever play consists basically on a big chunk of code that executes inside a loop. This loop goes on forever, and in each iteration of the loop, the state of the game is updated and changed according to different stimuli (user input, previous state of the game, etc). Well, the Update function in Unity is just that: a place to put all the instructions that you want Unity to execute on each iteration of the loop. To put it simple, what Unity will do on each iteration of this big loop is to take every object in your game and call its Update function. So, inside the Update function of each of your objects you will write the logic necessary to update their state.

Start

hen you start your game (hit the "play" button), all these objects must be first initialised; this is, their properties and attributes must be set up. This has to be done before we start the loop. Well, the Start function is the right place to do this. Unity will call the Start function of each one of your objects to initialise the properties. So inside of this function you will write the code necessary to set whatever attributes of that object you want to set.

I hope this helps you a little bit.

Comment
Add comment · Show 2 · 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 vbleyden · Apr 09, 2014 at 03:56 PM 0
Share

I'm working on units being damaged

I start them off all with an assigned var of 100, if i want the game to keep checking their hp i'd put thet script in the update function?

avatar image KiraSensei · Apr 10, 2014 at 12:53 AM 0
Share

Yes, it will check the hp at every frame.

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

24 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

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

The name 'Player' does not denote a valid type ('not found'). 1 Answer

How to call a c-sharp function from javascript? 1 Answer

Unityscript: Accessing functions from other scripts 1 Answer

Issues referencing variables between functions 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