![]() ![]() All 'public' variables will be available as parameters within the Inspector when the Script or GameObject the Script is attached to is selected and will also be available within other Scripts that have the Script attached as a component. So far all the above variables have been prefixed with the modifier 'public'. You can see some statistics on the performance brought via the use of Data Typing in this article on Performance Optimization. Public var demo : Vector3 = Vector3(1, 1, 1) ![]() Public var demo : String = "this is the variable 'playerSpeed' being assigned a String value" String - list of characters within quotation marks Some examples of common data types are: // VARIABLE DATATYPE DECLARATION & ASSIGNMENT EXAMPLES However, you should always define the data type of the information stored within the variable when it's declared so the compiler knows what data type it is dealing with and will be able to execute faster. They can be initialized or have a value assigned to them later on within a later part of the Script. basic variable declaration & assignment exampleĪs demonstrated above, variables don't have to have a value assigned to them immediately upon declaration. If you try to use a variable name already in use by Unity, like 'transform', you will get an error as variable names MUST be unique. ![]() 'demo test' - the camelBack / CamelCase Convention is used, resulting in 'demoTest'. For variable names of more than one word - e.g. They may be named anything you like but should be alphanumeric, begin with a lowercase letter, and be prefixed with the keyword 'var' as shown in the below example. Variables are containers for information. If there is enough interest I may publish a more in-depth tutorial for scripting in Unity, let me know in the comments.įor now, take a deep breath and let's dive straight in. #Unity simple delay function series#For those of you new to programming I'd suggest checking out the Nettuts+ Javascript from Null series should you want to go beyond the basics with Unity. All three are also supported by MonoDevelop, we will however be using JavaScript (UnityScript).Īt this stage previous programming experience would be helpful and will likely mean this section is a quick recap. NET libraries which support databases, regular expressions, XML, networking and so on. All three are equally fast and can interoperate. Unity provides several choices for programming in, JavaScript (UnityScript), C# and a form of Python - Boo. Step 5: A Quick Introduction to UnityScript However, it would be a little more interesting if they were to randomly spawn across the map at pre-determined spawn points. We could do this manually by dragging them from the Project Window onto the Terrain. With 'Bottom' selected add a Box Collider Component using the top menu, Component > Physics > Box Collider, and within the Inspector set the Box Collider's Position and Centre values to those shown below:īefore the user collects the pickups however we must spawn them over the map. Drag 'Bottom' onto 'Boundaries' to make it a child of the Boundaries GameObject. Make sure its Position within the Inspector is (0, 0, 0).ĭuplicate it using either RMB > Duplicate or by Ctrl + D and rename it 'Bottom'. Step 2: Using Colliders as Level BoundariesĬreate an empty GameObject using the top menu, GameObject > Create Empty, and rename it 'Boundaries'. ![]() We'll explore some of these functions in this tutorial.įor now, however, let's use several colliders to simply prevent our player walking off the edge of the map. This data is stored and made available to us via several functions, allowing us to trigger more specific behaviour when objects enter, occupy and leave a bounding box should we need to. When using Colliders the collision is handled for us, with the Collider calculating which part of the Bounding Box was intercepted first and controlling its reaction to the object(s) collided with. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |