Creating the script

As we did in Chapter 3, Let's Make Some Prefabs, we need to create a Player Controller (Script). Inside the Script folder, right-click and then CreateC# Script. We name it PlayerController. Now the script can be used as a component, meaning that it can be attached to a game object:

We can then open the Script by double-clicking on it. For those who didn't follow the previous project, here is a short recap. This is the code you should see:

using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 
 
public class PlayerController : MonoBehaviour { 
 
   // Use this for initialization 
   void Start () { 
          
   } 
    
   // Update is called once per frame 
   void Update () { 
          
   } 
} 

At the beginning, there are three lines that allow us to use libraries. Then, there is the class definition, in this case, named PlayerController. Inside it, there are two functions: Start() and Update(). The first is called every time this script starts, whereas the second is called at every frame.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset