Posts

Showing posts from January, 2021

Adding an Action Replay to a Game - Unity Game Development Tutorial

Image
In this Unity game development tutorial we're going to look at how we can add an action replay to our game. We'll look at how to add a standard replay, a rewind, a slow motion replay, and how to pause on any part of the replay. You can either watch the video version below or continue reading for written instructions. Right, we're going to start with the project we created in our ' Target Selection ' tutorial. In this tutorial, we created a tower of blocks that we can target with the mouse, before clicking the left mouse button to fire the ball. To add an action replay to our scene, we need to record what has happened in each frame. So the first thing we'll do is create a C# class to hold the information we want to record. To do this we'll click on the plus button on the project panel and select C# script. We'll call this script ActionReplayRecord. We'll double click to open it in Visual Studio and change it to match the following. using U

Common Gamepad Input Mistake Caused by Vector Normalization - Unity Game Development Tutorial

Image
In this Unity game development tutorial we're going to at how to solve a common mistake that's often made when processing input from a gamepad. You can either watch the video version below or continue reading for written instructions. Right, we're going to start with the project we created in our ' Character Rotation ' video. In this video we created a character that can move around our scene based on input from the keyboard or the gamepad. The problem is that the character always moves at the same speed no matter how far we move the gamepad thumbstick. There is no difference between moving the thumbstick all the way in a direction and moving it a fraction.  This probably isn't what we want. In most games, the character's speed will reflect the thumbstick movement. For example, the character may walk slowly when the thumbstick is moved a fraction and run when it is moved all the way. Right, let's look at our script to see where we're going wro

Require Component Attribute - Unity Quick Tip

Image
In this Unity quick tip we'll look at how we can use the RequireComponent Attribute to automatically add dependencies to a Game Object. You can either watch the video version below or continue reading for written instructions. We'll start with a scene containing a single cube. We'll add a script to our scene by clicking the plus button on the Project panel and selecting C# Script. We'll call this script Movement. We'll double click the script to open it in Visual Studio and change it to match the following. using UnityEngine; public class Movement : MonoBehaviour { void Start () { GetComponent< Rigidbody >().AddForce( Vector3 .forward * 100, ForceMode .Impulse); } } In the Start method we're getting the Rigidbody component and applying a force to it in the forward direction. Now, for this script to work, the Game Object it is assigned to must have a Rigidbody. To help ensure this is the case we can add the RequireCompon