Unity’s Beginner Scripting Tutorial is a good, free introduction to how C# works within Unity. It is not a great C# introductory tutorial. The CodeAcademy tutorial is a better intro tutorial. This tutorial is better for those who have a little scripting knowledge and want to see how C# and Unity work together. A lot of the code covered is specific to Unity and how Unity runs. It covers basic gaming code such as how to activate and deactivate game components, create, modify and destroy objects, use mouse and keyboard input, and keep track of time.
Watch the following lessons. As you are watching the lesson write the script from the lesson, attach it to a game object in Unity, and run the script.
- Scripts as Behavior Components
- Change the color of a cube to red, green, or blue depending on the key pressed.
- Add the colors yellow and orange for practice.
- Variables and Functions
- Write methods to multiply numbers and use debug.log to output the result to Unity’s console.
- Conventions and Syntax
- Write code to determine the position of the cursor and output statements to the console depending on the position of the cursor.
- Add a comment if the x position to too far left or right. Put the ground at 0f, too.
- IF statements
- Output statements depending on the time waited to press the space bar.
- Adjust the coffee, hotLimit, and coldLimit temps to see how this affects the running of the code.
- Use a for loop to output the number of enemies created.
- Make more enemies and add another comment each time an enemy is created.
Scope and Access Modifiers
- Skip this tutorial
- It is a good description of scope and public vs. private but the code is tough and confusing with objects and instances. Code is often too difficult for beginners.
- Awake and Start
- Simple code demonstrating the difference between the Awake and Start methods.
- Update and FixedUpdate
- Simple code demonstrating the difference between Update (per frame) and FixedUpdate (per second).
- The tutorial shows some of the complex math that Unity methods can do and when they might be used.
- You can skip this tutorial.
- Enabling and Disabling Components
- This tutorial describes how to enable and disable game object components.
- Activating Game Objects
- This tutorial describes how to activate and deactivate the entire game object.
- Translate and Rotate
- This tutorial describes how to get objects to move and rotate under keyboard control.
- Look At
- This tutorial describes how to get objects to automatically turn towards other objects.
After each lesson, show Mr. Didier your code. You should be able to work through at least 4 lessons per week. Most of them are short lessons.
There are more lessons in the Beginner Scripting tutorial, but the first few are enough to get you going. If you want more practice with scripting and Unity, the other lessons are great practice with more complex coding.