A Quick Look into Gameplay Programming with Unity
Tags: unity3d, gameplayprogramming, beginners
Published: 2019-08-08 14:49:11

---
title: A Quick Look into Gameplay Programming with Unity
published: True
description: A look at the tools Unity gives you to build your own games
tags: Unity3D, GameplayProgramming, Beginner
---


Since graduating Flatiron School back in May of this year, I have put a lot of my focus in coding on my personal passion: game development. I learned C# in order to script in Unity, a 3D game development program that I learned how to use back in college. However I was never properly taught how to code before my bootcamp experience so I’d say that my eyes have been opened like never before. Now I’d like to share with you some of the things I’ve learned over the past few months.

Lets jump right in!

###What Are Components?
In Unity there are bits of code that can be coupled on individual objects. These bits of code are called components, because they are modular and can be appended on to many different types of game objects in order to increase functionality. You can think of a component as a ball and socket system where components can interface with other components extremely smoothly. 

When you’re developing gameplay systems in Unity you are basically putting these components together in a cohesive manner so that they talk to each other and create a fun gameplay loop for the player. Unity uses C# in order to write scripts that function as components on these objects, so you can not only  make a simple health variable, but you can create a regenerative health system that can be applied to anything with a simple drag and drop.

![Component Example](https://i.imgur.com/q0JGG48.png "Component Example")

###Getting User Input

To get user input for movement is actually very simple. In Unity, you just need to access the [Input class](https://docs.unity3d.com/Manual/class-InputManager.html) and specify by String which Input you’d like to access.

{% replit @ScottSlatton/OvercookedRudeLivecd %}

###Making Variables Available Inside the Inspector

You can make variables inside your script accessible from the outside in the Inspector by using the “Public” flag in front of your variable declarations.

As you can see in the script above we've made our movement speed accessible in the inspector.

![Accessible Variable Example](https://i.imgur.com/YONqP9Q.png "Here Move Speed is available to change in the Inspector")

Not only can we utilize the “Public” keyword to make integers, floats and strings accessible, we can make components and therefore their properties accessible as well.

###Collisions

Collisions are where Sir Isaac Newton steps in and adds some fun physics to our game. You can build entire games from just Rigidbody collision mechanics (See Angry Birds). Like much of everything in Unity Colliders come as components, specifically Rigidbody and Colliders.

From the [Unity Docs:](https://docs.unity3d.com/Manual/RigidbodiesOverview.html) 

_A **Rigidbody** is the main component that enables physical behaviour for a **GameObject**. With a Rigidbody attached, the object will immediately respond to gravity. If one or more **Collider** components are also added, the **GameObject** is moved by incoming **collisions**._

Colliders on the other hand are the invisible boundaries that actually bump into each other.

So if we want our game objects to be influenced by physics, we need both a Rigidbody component and a Collider. If you don’t have a Collider, objects will be able to pass through other objects. If you are missing a Rigidbody, the object will not be influenced by physics but will repel other objects with Colliders. This is an important feature because we can make our aspects of our level, like the ground and closed doors, impassable for our players.

Those are a few of the tools we can leverage in Unity to create the games that people love to play. Next blog post I’ll go into Triggers, Raycasting, and interactions between different scripts.