Introduction to scripting with Unity / PDF
Introduction to scripting with Unity / PDF
1. Aims of this tutorial
Scripting is how the user defines a game’s behaviour (or rules) in Unity. The recommended programming
language for Unity is Javascript, however C# or Boo can also be used. This tutorial will cover the
fundamentals of scripting in Unity and also introduce key elements of the Application Programming Interface (API).
You can think of the API as code that has already been written for you which lets you concentrate on your game design and also speeds up development time.
A good understanding of these basic principles is essential in order to harness the full power of Unity.
2. Prerequisites
This tutorial focuses on the scripting element of Unity, it is assumed you are already familiar with Unity’s interface (if not you should read the Unity GUI tutorial).
In order to make scripting easier to understand, it is preferable to have a code editor that has syntax
highlighting support for Javascript. This means that reserved words (syntax used by Javascript itself) are
coloured differently than user defined words. One such editor is SubEthaEdit.
3. Naming Conventions
Before we begin, it is worth mentioning some conventions in Unity.
Variables - begin with a lowercase letter. Variables are used to store information about
any aspects of a game’s state.
Functions - begin with an uppercase letter. Functions are blocks of code which are written once and can then be reused as often as needed.
Classes - begin with an uppercase letter. These can be thought of as collections of
functions.
Tip: When reading example code or the Unity API, pay close attention to the first letter of
words. This will help you better understand the relationship between objects.
Table of Contents
1. Aims of this tutorial
2. Prerequisites
3. Naming conventions
4. Player Input
5. Connecting variables
6. Accessing components
7. Instantiate
8. Debugging
9. Common Script Types
Scripting is how the user defines a game’s behaviour (or rules) in Unity. The recommended programming
language for Unity is Javascript, however C# or Boo can also be used. This tutorial will cover the
fundamentals of scripting in Unity and also introduce key elements of the Application Programming Interface (API).
You can think of the API as code that has already been written for you which lets you concentrate on your game design and also speeds up development time.
A good understanding of these basic principles is essential in order to harness the full power of Unity.
This tutorial focuses on the scripting element of Unity, it is assumed you are already familiar with Unity’s interface (if not you should read the Unity GUI tutorial).
In order to make scripting easier to understand, it is preferable to have a code editor that has syntax
highlighting support for Javascript. This means that reserved words (syntax used by Javascript itself) are
coloured differently than user defined words. One such editor is SubEthaEdit.
3. Naming Conventions
Before we begin, it is worth mentioning some conventions in Unity.
Variables - begin with a lowercase letter. Variables are used to store information about
any aspects of a game’s state.
Functions - begin with an uppercase letter. Functions are blocks of code which are written once and can then be reused as often as needed.
Classes - begin with an uppercase letter. These can be thought of as collections of
functions.
Tip: When reading example code or the Unity API, pay close attention to the first letter of
words. This will help you better understand the relationship between objects.
Introduction to scripting with Unity / PDF
0 commentaires: