Let's conclude our discussion on programming in Unity by talking about some of the Unity specific things you should understand. Overall, we say that Unity is an event-driven environment. You often add functions to your classes to respond to events that occur while the game is playing, such as Start, which is called when the gameObject starts in the scene, and update, which is called every time through the game event loop. There are a few other events that happen when you start playing, including awake, OnEnable and Start in that order. These are great places to set up things like initialize variables. During the game event loop, the update and LateUpdate events happen in that order. This is a great way to do things or check on things while the game is playing. There are several other events that you can respond to, such as FixedUpdate for updates that are synchronized with the physics engine, and events for collisions and triggers, as well as events for mouse input on gameObjects, such as mouse up and mouse down. There are many other built-in events. You can also create and respond to your own custom events as well. One common thing that we do in scripts is modify gameObjects in some way. When a script is attached to a gameObject, we can reference the gameObject in the script as this dot gameObject, or just gameObject for short. For example, these two start functions do the exact same thing, they set the gameObject that the script is attached to to inactive. This is the same thing as clicking the active, inactive check box in the inspector, except of course, it is done dynamically at playtime. In this script, the name of the gameObject is outputted to the console Window in the Unity editor twice, that is, both lines do the same thing. If we want to reference a gameObject that the script is not attached to, we can do this in a number of ways. We can have a public variable of type gameObject that we attach to another gameObject or prefab in the Unity editor. Or we can search for the gameObject using gameObject.find to search for a gameObject by name. Or we can search for the gameObject using gameObject.find with tag, to search for a gameObject with a particular tag. With both of the fine techniques, you need to make sure that you only have one gameObject with a name or tag that you're searching for. Otherwise you're not sure which gameObject you'll get a reference to. You can see in this example that once we have the reference to the gameObjects, we can call the set active function in the same way. Once we have a reference to a gameObject, we often want to modify a component of that gameObject. Every property that you see in the Unity editor for component can be referenced and often modified through code. For example, let's say we want to move a gameObject along the x-axis, we can do this through its transform. In code, we can reference the transform of a gameObject through the transform property of the gameObject or gameObject dot transform. The transform property has a position property, which in turn has an x property. So gameObject.transform.position.x is how we would reference or change the x position of a gameObject. We could do this in the update function, so the gameObject moves every frame update. It turns out that the transform class has a built-in translate function that will essentially do the same thing. Alternatively, we could use that to move the gameObject along the x-axis. The function takes three arguments, one for x, one for y, and one for z. As you can see here, I'm only modifying the x. Not all components are properties of the gameObject like transform. To get a reference to any component type on a gameObject, you can use the gameObject.GetComponent function and then specify the type of the component. Once you do that, you can then manipulate the component. For example, this script gets a reference to the rigid body component attached to the gameObject and sets it to a variable named rb. It then modifies the Use Gravity variable, setting it to true or odd. Another way to reference a component is to setup a public variable in your a class. This will make the variable appear in the Unity Editor Inspector. You can then drag and drop a gameObject with the specified component to the variable in the Inspector. Here are common component types that you might reference in code. Once you get a reference to the component, you can use the components properties and methods to do things dynamically as the game plays. A lot of game coding is simply manipulating gameObjects and their components. When you're writing Unity scripts, the scripting API documentation that comes with Unity and is available on the web is an absolutely essential resource. You can use it to look up, for example, any component type and then find the properties and methods that allow you to work with the component through code. Another common thing that you want to do in code is the spawn or instantiate gameObjects into the game scene. This can be done, for example, to spawn enemies are create projectiles that the player fires. Here is an example script that instantiates a prefab. Once you attach the script to a gameObject, you can then set the prefab variable in the Unity Editor to be the prefab that you want to spawn. While the game is playing this code will run on each frame update. It checks to see if the user is pushing the fire button. If so, then it will get the current position and rotation of the gameObject that the script is attached to. Then it will instantiate a new gameObject based on the prefab at this position and rotation. There are ways to simplify this code, but I wrote it more verbose to hopefully help an understanding of the process. If some of the concepts we just discussed are very foreign to you, don't worry, you're learning a new language. Remember, it takes time and effort to get up that learning curve. Also, remember, Unity has excellent documentation. I recommend that you reference the online documentation often, especially the API scripting reference. Microsoft also maintains good online documentation on C-sharp in general. Unity also has a vibrant community with a very active forum. If you have a question on how to do something, search the forums, someone probably already has asked the question and you can find an answer. If you cannot find an answer, you can always post your questions in the forums and someone will likely get back to you or just Google it. There are many great programming resources out there, such as Stack Overflow, which also has very active forums. There are also many great video tutorials on YouTube. Wow, we just did a rapid-fire quick-start of programming in C-sharp with Unity. I hope your mind is not too blown. This lecture should give you the base knowledge needed to understand the code walk-throughs that we'll be doing across the rest of the course. I recommend working through your current class assignment and then coming back and watching this lecture again. Like learning any new language, it takes practice, experience, and some patience to get good at it. Once again, this is not really a programming course, but hopefully this and the projects that you'll be doing will help improve your programming chops. No matter what your role, programmer, artist or designer, the more programming that you know, the better off you'll be when it comes to game development. Happy coding.