Hello Light!

Start a new project and change layout

  • Open Unity and create a new project.
  • Go to Window / Layouts. Select 2 by 3

Create a new 3D object. A Plane (Looks like a flat square surface)

  • Reset it’s position to 0, 0, 0 (you can also use the small cog in the upper right corner at transform in the inspector and click reset )
  • Scale the plane to 1000, 1000, 1000. Yes that big. (This way it make for a nice horizon)

Create a second 3D object. A sphere (A ball)

  • Reset it’s position again to make sure its at 0 ,0, 0
  • Scale it to 5, 5, 5
  • Move it’-s position to 3 on the Y axis to make it hover a bit above the ground.


We should now (hopefully) have something that looks like this in your game view tab

Time to Code! (Adding logic via C# scripting)

Now we will add logic, so that, whenever we press SPACE the light in the scene (game) will be toggled ON or OFF. To do this we need to create some logic. To implement logic like this we need to create a script that let us take input from the user (SPACE being pressed) and make it access the Light game object and its properties.
 
  • Start with right clicking and choose: Create a new C# script and name it LightSwitch.
  • Drag and drop the script on top of the Directional Light game object in the Hierarchy tab. 
  • (You can also click on the directional light in the hierarchy tab and then in the inspector choose Add Component and select your C# script )
  • Double click on the script top open it for edit. 

That should open up MonoDevelop which is the program used to edit scripts for Unity. 
You should get a basic code template that look something like this:

using UnityEngine;
using System.Collections;

public class LightSwitch : MonoBehaviour{

    // Use this for initialization
    void Start (){
    
    }
    
    // Update is called once per frame
    void Update (){
    
    }
}

OK, So what next? 

Well, what do we want our script to do ? 
  • We need tell the script about our game object, and that it should look for a LIGHT component. 
  • We also need a variable to hold the information about that component. 
  •  Listen for user input. In our case SPACE being pressed.
  • Toggle the light component ON or OFF.