“Tipsy Tower” prototype made with Unity and C#

Read all posts about "" game
If you enjoyed the Tipsy Tower prototype made with Construct here I am with the Unity version, powered with the free platformer art tileset provided by Game Art 2D Let’s start from the result, here’s what I built:
Click to drop the crate. Now it’s time to have a look at my Unity scene: Let me explain the assets, one by one: Crate image: the PNG image of the crate. Ground image: the PNG image of the ground. Ground: it’s just “ground image” placed into the game with a Rigidbody 2D component at its default settings (ececpt Body type: Static) and a Box Collider 2D component at its default settings. Moving Crate prefab: it’s the prefab of the moving crate, which includes the crate image and the moving crate script. Moving Crate: the “moving crate prefab” placed into the game Physics crate prefab: it’s the prefab of the physics crate, which includes the crate image and the physics crate script. It has a Rigidbody 2D component at its default settings and a Box Collider 2D component at its default settings. Now, let’s have a look at the scripts, the core of the game. The first one is the physics crate script, which only removes the crate from the game when it’s not longer on the stage. crateScript.cs using System.Collections; using System.Collections.Generic; using UnityEngine; public class crateScript : MonoBehaviour { // this function is executed when the game object become ivisible, in this case // when it leaves the stage void OnBecameInvisible(){ // destroying game object Destroy (gameObject); } } Now, the moving crate script, which is only a non phyiscs driven crate moving from left to right: movingCrateScript.cs using System.Collections; using System.Collections.Generic; using UnityEngine; public class movingCrateScript : MonoBehaviour { // this function is executed at each frame void Update () { // since we can’t just change the x position of a game object, we have to create a position which is the same // as the original game object position Vector3 newPosition = transform.position; // this is how we can set a tween, using PingPong on a variable (in this case the time), // so that it is never larger than length and never smaller than 0. // The returned value will move back and forth between 0 and 4.4f newPosition.x = Mathf.PingPong (Time.time * 5.0f, 4.4f) – 2.2f; // and finally we apply new position to game object’s position transform.position = newPosition; } } The main script waits for player input, handles physics crate creation and hides the moving crate. MainScript.cs using System.Collections; using System.Collections.Generic; using UnityEngine; public class MainScript : MonoBehaviour { // crateObject is the physic crate prefab public GameObject crateObject; // a variable used only inside this class, for PRIVATE use. // canDrop is true if the player can drop a crate, false when the player can’t private bool canDrop = true; // this function is executed at each frame void Update () { // checking for player input AND canDrop to be true. // it means the player can drop a crate if (Input.GetButtonDown (“Fire1”) && canDrop) { // set canDrop to false canDrop = false; // find an object called “movinCrate” and store it into movingCrate variable GameObject movingCrate = GameObject.Find (“movingCrate”); // calling cangeAlpha function to set movingCrate’s alpha to zero (completely transparent) changeAlpha (movingCrate, 0f); // instantiate a crateObject instance and assign it to physicsCrate variable GameObject physicsCrate = Instantiate(crateObject); // set physicsCrate position as the same of movingCrate position physicsCrate.transform.position = movingCrate.transform.position; // starting a coroutine – set a s waitForCrate function. // the interesting thing of a coroutine is it can be paused at any point using the yield statement StartCoroutine (waitForCrate(movingCrate)); } } // the IEnumerator allows the program to yield things like the WaitForSeconds function, // which lets you tell the script to wait without hogging the CPU IEnumerator waitForCrate(GameObject crate){ // this means “wait 2 seconds” yield return new WaitForSeconds(2); // setting canDrop to true again, now the player can drop another crate canDrop = true; // setting moving crate alpha to 1 changeAlpha (crate, 1f); } // this function changes the alpha of a game object void changeAlpha(GameObject sprite, float alpha){ // since we can’t just change the alpha, we have to create a color which is the same // as the original game object color Color color = sprite.GetComponentdownload the Unity project.

Get the most popular Phaser 3 book

Through 202 pages, 32 source code examples and an Android Studio project you will learn how to build cross platform HTML5 games and create a complete game along the way.

Get the book

214 GAME PROTOTYPES EXPLAINED WITH SOURCE CODE
// 1+2=3
// 100 rounds
// 10000000
// 2 Cars
// 2048
// A Blocky Christmas
// A Jumping Block
// A Life of Logic
// Angry Birds
// Angry Birds Space
// Artillery
// Astro-PANIC!
// Avoider
// Back to Square One
// Ball Game
// Ball vs Ball
// Ball: Revamped
// Balloon Invasion
// BallPusher
// Ballz
// Bar Balance
// Bejeweled
// Biggification
// Block it
// Blockage
// Bloons
// Boids
// Bombuzal
// Boom Dots
// Bouncing Ball
// Bouncing Ball 2
// Bouncy Light
// BoxHead
// Breakout
// Bricks
// Bubble Chaos
// Bubbles 2
// Card Game
// Castle Ramble
// Chronotron
// Circle Chain
// Circle Path
// Circle Race
// Circular endless runner
// Cirplosion
// CLOCKS - The Game
// Color Hit
// Color Jump
// ColorFill
// Columns
// Concentration
// Crossy Road
// Crush the Castle
// Cube Jump
// CubesOut
// Dash N Blast
// Dashy Panda
// Deflection
// Diamond Digger Saga
// Don't touch the spikes
// Dots
// Down The Mountain
// Drag and Match
// Draw Game
// Drop Wizard
// DROP'd
// Dudeski
// Dungeon Raid
// Educational Game
// Elasticity
// Endless Runner
// Erase Box
// Eskiv
// Farm Heroes Saga
// Filler
// Flappy Bird
// Fling
// Flipping Legend
// Floaty Light
// Fuse Ballz
// GearTaker
// Gem Sweeper
// Globe
// Goat Rider
// Gold Miner
// Grindstone
// GuessNext
// Helicopter
// Hero Emblems
// Hero Slide
// Hexagonal Tiles
// HookPod
// Hop Hop Hop Underwater
// Horizontal Endless Runner
// Hundreds
// Hungry Hero
// Hurry it's Christmas
// InkTd
// Iromeku
// Jet Set Willy
// Jigsaw Game
// Knife Hit
// Knightfall
// Legends of Runeterra
// Lep's World
// Line Rider
// Lumines
// Magick
// MagOrMin
// Mass Attack
// Math Game
// Maze
// Meeblings
// Memdot
// Metro Siberia Underground
// Mike Dangers
// Mikey Hooks
// Nano War
// Nodes
// o:anquan
// One Button Game
// One Tap RPG
// Ononmin
// Pacco
// Perfect Square!
// Perfectionism
// Phyballs
// Pixel Purge
// PixelField
// Planet Revenge
// Plants Vs Zombies
// Platform
// Platform game
// Plus+Plus
// Pocket Snap
// Poker
// Pool
// Pop the Lock
// Pop to Save
// Poux
// Pudi
// Pumpkin Story
// Puppet Bird
// Pyramids of Ra
// qomp
// Quick Switch
// Racing
// Radical
// Rebuild Chile
// Renju
// Rise Above
// Risky Road
// Roguelike
// Roly Poly
// Run Around
// Rush Hour
// SameGame
// SamePhysics
// Save the Totem
// Security
// Serious Scramblers
// Shrink it
// Sling
// Slingy
// Snowflakes
// Sokoban
// Space Checkers
// Space is Key
// Spellfall
// Spinny Gun
// Splitter
// Spring Ninja
// Sproing
// Stabilize!
// Stack
// Stick Hero
// String Avoider
// Stringy
// Sudoku
// Super Mario Bros
// Surfingers
// Survival Horror
// Talesworth Adventure
// Tetris
// The Impossible Line
// The Moops - Combos of Joy
// The Next Arrow
// Threes
// Tic Tac Toe
// Timberman
// Tiny Wings
// Tipsy Tower
// Toony
// Totem Destroyer
// Tower Defense
// Trick Shot
// Tunnelball
// Turn
// Turnellio
// TwinSpin
// vvvvvv
// Warp Shift
// Way of an Idea
// Whack a Creep
// Wheel of Fortune
// Where's my Water
// Wish Upon a Star
// Word Game
// Wordle
// Worms
// Yanga
// Yeah Bunny
// Zhed
// zNumbers