Unity3D development: Unity3D script Overview

Source: Internet
Author: User

Like other 3D software, Unity3D, as a player-like 3D integration software, has a good time-level relationship. For example, the Start language is always executed once during player initialization and then no longer executed. For example, the following example is written in JS. On the menu bar, select --> and drag the following code to any object in Hierarchy list.

You will see this sentence in the console panel in the lower left corner when the Player starts playing, proving that your Game player has started to work. 5.1:


Fig 5.1
Note: This console will often be used when you buy it, because it can be used for debugging your code snippets and prompt boxes with errors in your program, the detailed error cause is prompted .)
Of course, with the initialization function, the frame swiping function will Update), all the code in this function will be executed every time the player plays a frame. For example, the following example is written in JS. On the menu bar, select --> and enter the following code:

This code displays the time consumed since the beginning of the game each time the player plays a frame.
Unity3D has a very powerful interface processing function. You can create any empty interface for the object in the code to interact with the corresponding type of object. For example, an example written in JS is as follows, on the menu bar, select --> and enter the following code:


This Code adds an initial speed in the Z axis for the object. If no external force is applied, the object will always move at a speed of 5 along the Z axis. After you drag the code to an object, the initial speed of the code can be modified in its attribute Panel as an interface. 5.2:

Fig 5.2
In addition to numbers, interfaces can also be objects. For example, in the following example, select --> in the menu bar and enter the following code:

You can drag this code to any object in the Hierarchy list bar, because it defines a Transform class interface object cubeGO, so it is almost irrelevant to the drag object. After the object is successfully dragged to the attribute Panel of the object, you can see such an attribute roll-up column. There is a clearly undefined object fill column behind cubeGO, then we drag the object we want to make it move to it. When we run the game, press the "G" key to see the dragged object as the reference object of "cubeGO", moving towards the Z axis.

Precautions for C # Script Programming in Unity3D

Maybe you are a C # programming expert before learning Unity3D. However, C # In Unity3D is not as powerful as C #. C # In Unity3D must all inherit from MonoBehaviour. The complete code of C # Script is as follows:

In addition, it does not support space naming, but officially said they are likely to support this feature in future versions.
In Unity3D, JavaScript and C # Script have almost the same programming effect. It just sets up different programming modes for different programmers. In addition, the Code objects written in JavaScript can be used with the code objects written in C # Script without any conflict.

Modify the MonoDevelop editor to the default Unity3D editor.

Generally, the default Unity3D editor is "UniSciTE", which is very lightweight and quick to use, just like notepad.
But if you want to develop some large projects, it is clear that the simple functions of "UniSciTE" are not enough to support its work. However, every time you edit a script, you can use "MonoDevelop" to open it one by one, which may be quite troublesome. So we need to make some settings in Unity3D to make "MonoDevelop" the default Script Editor. The specific steps are as follows: Find --> in the menu bar, find it in the pop-up dialog box, and select the drop-down box next to it to browse to the place where our "MonoDevelop" executable files are stored. The path is usually in the Unity3D folder.
After setting it, click the script file in Unity3D again, and you will find that it can be opened with the "MonoDevelop" software, but it will be a little slower at one time, because "MonoDevelop" needs to load a lot of things.
Of course, if you are a loyal programmer of C # and Visual Studio, you can also set the path of Visual Studio in the same way, make Visual Studio the default editor for your Unity3D script.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.