Allan Didier

GD Unity Beginner Scripting Tutorial

Unity Scripting Tutorial

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. 

Project Description

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.

  1. Scripts as Behavior Components
    1. Change the color of a cube to red, green, or blue depending on the key pressed. 
    2. Add the colors yellow and orange for practice.
  2. Variables and Functions
    1. Write methods to multiply numbers and use debug.log to output the result to Unity’s console.
  3. Conventions and Syntax
    1. Write code to determine the position of the cursor and output statements to the console depending on the position of the cursor.
    2. Add a comment if the x position to too far left or right. Put the ground at 0f, too.
  4. IF statements
    1. Output statements depending on the time waited to press the space bar. 
    2. Adjust the coffee, hotLimit, and coldLimit temps to see how this affects the running of the code.
  5. Loops
    1. Use a for loop to output the number of enemies created.
    2. Make more enemies and add another comment each time an enemy is created.
  6. Scope and Access Modifiers
    1. Skip this tutorial 
    2. 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.
  7. Awake and Start
    1. Simple code demonstrating the difference between the Awake and Start methods.
  8. Update and FixedUpdate
    1. Simple code demonstrating the difference between Update (per frame) and FixedUpdate (per second).
  9. Vector Maths
    1. The tutorial shows some of the complex math that Unity methods can do and when they might be used.
    2. You can skip this tutorial.
  10. Enabling and Disabling Components
    1. This tutorial describes how to enable and disable game object components.
  11. Activating Game Objects
    1. This tutorial describes how to activate and deactivate the entire game object.
  12. Translate and Rotate
    1. This tutorial describes how to get objects to move and rotate under keyboard control.
  13. Look At
    1. 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.