3
votes

I am relatively new to unity and scripting. I have a few questions regarding how scripting works with GameObjects.

1) Each GameObject can have a script added to them. When are these script called? For example, void Update() gets called every frame. Does this mean every script from every GameObject will get called every frame?

2) How does Unity know when to call things like MouseDown or Touch begin?

3) When does each Start() get called for each script?

Any link regarding this information will greatly help.

Thanks

2
The unity tag is for Microsoft Unity. Do not misuse it.Lex Li
@LexLi relax, whats the big deal, its just a tagbluejayke
@bluejayke relax, >6 years.Lex Li

2 Answers

4
votes

I have limited knowledge on the subject of Unity, but I'll do my best to help you here.

1) Scripts are named whatever you want to name them. Whether you want to name them 'MovementBehaviour' or 'ShootMechanic', you can name these scripts as you wish. These scripts can be written in C#, Javascript (more often referred to as 'Unityscript', which is the altered version of Javascript that devs can use), or a variant of Python called 'Boo'. When you create a new script, the scripts are automatically given void Start() and void Update() methods. These methods can be removed if the dev does not need/want them, but yes, the Update() method, if included will be called once per frame.

2) MouseDown and TouchBegin are just parts of Unity that are built in through the InputManager, a nifty tool which allows for devs to easily add control to items (whether that item be a ball or a camera). Using this InputManager, you can easily add controls using vertical/horizontal movement, jumping, shooting, and a plethora of other commands. Most movement methods are added in the Update() method that you were curious so as to allow for fluid and continuous movement. You can use this for help on this.

3) From the Unity documentation, 'Start is called on the frame when a script is enabled just before any of the Update methods is called the first time.' More information on this can be found here.

1
votes

You can find very nice video tutorials by Unity Technologies from following mentioned linked for Beginners about Editor, Animation, Physics, Graphics and Scripts

http://unity3d.com/learn/tutorials/modules

or you can directly go to their youtube page:

http://www.youtube.com/user/Unity3D

or if you have any specific question you can ask :)