All Projects → antfarmar → Unity-Tanks-Tutorial

antfarmar / Unity-Tanks-Tutorial

Licence: other
Unity Tanks Tutorial: Completed Project Files & Phases Summary

Programming Languages

C#
18002 projects
ShaderLab
938 projects

Projects that are alternatives of or similar to Unity-Tanks-Tutorial

ImpossibleOdds-TacticalCamera
Camera system for tactical world overviews in Unity games.
Stars: ✭ 14 (-36.36%)
Mutual labels:  unity-3d
Streaming Map Demo
Demo of Streaming Binary Data format in a Unity Application for Streaming Maps in realtime
Stars: ✭ 24 (+9.09%)
Mutual labels:  unity-3d
streamdeck-unity
Enables Stream Deck integration with Unity.
Stars: ✭ 22 (+0%)
Mutual labels:  unity-3d
TanksNetworkingInAzure
Tanks Networking demo project from Unity Store that can be deployed in Azure Cloud and scaled using Kubernetes
Stars: ✭ 20 (-9.09%)
Mutual labels:  unity-3d
UnityGameTemplate
Template with all necessary stuff taken care, just create your games main features.
Stars: ✭ 221 (+904.55%)
Mutual labels:  unity-3d
Mage
Mage is a 3D Game Engine, built on top of THREE.js. It features Unity-like scripting, AMMO.js powered physics workers, an Infernojs powered UI and a clean API. Under (very) active development.
Stars: ✭ 76 (+245.45%)
Mutual labels:  unity-3d
download.unity.com
Unity Download http://unity3d.com/unity/download/archive
Stars: ✭ 90 (+309.09%)
Mutual labels:  unity-3d
unity-tools
A Visual Studio Code Extension to provide some tools for Unity development
Stars: ✭ 25 (+13.64%)
Mutual labels:  unity-3d
metrica-plugin-unity
Unity plugin for Yandex AppMetrica SDK
Stars: ✭ 24 (+9.09%)
Mutual labels:  unity-3d
Velocity
Weird jumping game
Stars: ✭ 32 (+45.45%)
Mutual labels:  unity-3d
Unity3D-Cars
A project built for a Renaissance Coders tutorial to introduce vehicle physics.
Stars: ✭ 60 (+172.73%)
Mutual labels:  unity-3d
Game-Assets-And-Resources
Free and paid game assets and game resources for 2D games, 3D games, mobile games, Steam games, Unity games, and other games.
Stars: ✭ 164 (+645.45%)
Mutual labels:  unity-3d
QuietVR
A Quiet Place in VR: Generate any 3D object with your voice. It's magic!
Stars: ✭ 17 (-22.73%)
Mutual labels:  unity-3d
cepathfind
a path find for tilebase game in unity
Stars: ✭ 30 (+36.36%)
Mutual labels:  unity-3d
bhl
bhl is a strictly typed programming language specifically tailored for gameplay logic scripting.
Stars: ✭ 20 (-9.09%)
Mutual labels:  unity-3d
GuneyOzsanOutThereMusicVideo
Procedurally generated, real-time, demoscene style, open source music video made with Unity 3D for Out There by Guney Ozsan.
Stars: ✭ 26 (+18.18%)
Mutual labels:  unity-3d
UnityGlobalTextSystem
Allow the user to 'change' the default font in Unity from "Arial" to a font of their liking.
Stars: ✭ 21 (-4.55%)
Mutual labels:  unity-3d
JsonFormatter
Easy, Fast and Lightweight Json Formatter. (Serializer and Deserializer)
Stars: ✭ 26 (+18.18%)
Mutual labels:  unity-3d
TsukiSuite
A toolsuite created to make Unity development easier
Stars: ✭ 23 (+4.55%)
Mutual labels:  unity-3d
com.unity.netcode.gameobjects
Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.
Stars: ✭ 1,678 (+7527.27%)
Mutual labels:  unity-3d

Unity Tanks Tutorial

Concepts Learned In Each Phase

Index

  1. Scene Setup
  2. Tank Creation & Control
  3. Camera Control
  4. Tank Control
  5. Shell Creation
  6. Firing Shells
  7. Game Managers
  8. Audio Mixing

01. Scene Setup

Basic scene setup

General

  • Dragging asset models into the scene or hierarchy
  • Frame selecting game objects in scene: dbl-click game object in Hierarchy, or 'F' key in Scene when selected

Lighting

  • Dedicated window for lighting options
  • Precomputed Real Time GI selected for use
    • Baking the lighting (a lengthy bg process)
    • Low resolution OK for lowpoly models
  • Ambient light source & color vs. skybox

02. Tank Creation & Control

How to add the tank artwork and components to let the player control the tank.

General

  • Layers
    • For collider interaction isolation
    • Only collider owner needs to be on layer (parent GO, not children)
  • Duplication of GameObjects (Ctrl+D or right-click context menu)
  • Project Settings
    • Input Manager: configuring input control & names

Components

  • Component adding, setup, & collapsing
    • Rigidbody
      • req'd for Physics system
      • constraints on axes (position/rotation)
      • Kinematics: turn on/off (receive physical forces/no forces)
    • Colliders (primitive)
      • reports physics events (collisions) to Rigidbody
      • Trigger vs. Physical events
      • proper sizing for model
    • Audio Source
      • Populating references using "Circle Select" in Inspector
      • versus dragging from Project Assets folders
      • Empty references to be populated at runtime via scripting
    • Scripts
      • are also Components (provided they extend from Monobehaviour)

Prefabs

  • Dragging configured scene objects from Hierarchy into Project Prefabs folder
    • and vice versa
  • Prefab options: Select, Revert, Apply
    • between prefab & scene object linkage
    • Applying changes from changed Hierarchy/Scene game objects to prefabs.
    • Blue vs gray text in Hierarchy: Saved vs. unsaved changes to prefabs from scene gameobjects
      • Also bold fields in Inspector are unsaved changes to prefabs

Particle Systems

  • World vs. Local simulation space
  • Simulate over time vs. distance
  • Various options for behavior

Scripting

  • Script editing, compiling, serializing workflow in Unity
  • Console window messages for debugging.
  • Public vs. Private fields/member variables
    • relation to Inspector view (public fields show up for editing & populating references)
    • UnassignedReferenceExceptions when forgetting to assign reference in Inspector panel.
  • Inspector serialized values override values assigned in the script's public/serializable variables.
  • Dynamically referencing & manipulating Components at runtime
  • Variable naming conventions
    • e.g. m_Name denotes class member variable (scoping mnemonic)
  • TankMovement (inherits from MonoBehavior)
    • Script Component for Tank GameObject to control its movement
    • coding MonoBehaviour Event methods (Awake, Start, Update, etc)
  • Vector manipulation math for Rigidbody movement by applying forces via method calls
  • Quaternion representation in Unity for rotations of Transformations
    • Quaternion.Euler() method for easy Euler angle conversions

03. Camera Control

How to create a Camera rig which pans and zooms to keep all tanks on-screen at once.

  • Creation of an empty GameObject called CameraRig to house a Script Component: CameraControl.cs
  • Rig becomes parent of the existing MainCamera
  • Scripted to keep both tanks in view: Pan and Zoom (i.e. move & resize frustum)
    • Tanks will stay in camera's frustum: area b/w near & far clip plane
    • Perspective frustum: variable size clip planes
    • Orthographic frustum: same size clip planes, hence no change in scale over distance
    • Orthographic Camera size in relation to aspect ratio (16:9) & aspect (1.77).
  • GameObject.GetComponentInChildren() method OK if child component type is unique.
  • [HideInInspector] attribute to prevent public member from being serialized to Inspector.

04. Tank Health

Setup tank damage, update UI heal slider based on health value, tank deactivation on death

  • Using a Unity UI Slider as a radial health bar.
  • UI Elements: Canvas, Slider, EventSystem
  • EventSystem Input Module component in Inspector
    • Axis setup along with InputManager
  • Canvas Scaler (Script) component for helping developing multiresolution apps
  • Canvas component Render modes: Screenspace vs. Worldspace
  • Rect Transform component in all UI elements.
  • Anchor presets button to edit anchors (Shift/Alt)
  • Top to Bottom rendering of UI child elements of Canvas (as found in the Hierarchy)
  • Instantiating inactive game objects (e.g. particle systems) to cache them until ready for use.
    • Also, setting them inactive again instead of destroying them then reinstantiating again.
    • Caching like this (inactive->active) saves on garbage collection calls.

05. Shell Creation

Create a ballistic shell for the tank & a radius for explosion forces

  • Collider triggers for simply creating callbacks in scripts to react to, instead of physical forces.
  • Physics.OverlapSphere(pos,radius,layer) method to get an array of colliders touching/inside a specified sphere.
  • Rigidbody.AddExplosionForce(force,pos,radius) to simulate explosive forces.
  • Component references can also be used to get other component references on same GameObject via GetComponent<>().

06. Firing Shells

How to fire projectiles, and make a UI & sound effect to accompany the mechanic.

  • Re-appropriate a UI Slider to make an aiming guide.
  • Shells are unoptimally instantiated and destroyed every fire. Object pooling pattern would solve this.

07. Game Managers

Game loop architecture using coroutines and textual UI creation for messaging players.

  • Text UI GameObject creation and usage, along with Shadow script component for effect.
  • [Serializable] attribute on classes are serialized for view in the Inspector.
  • ColorUtility.ToHtmlStringRGB(Color) for converting an rgb color to HTML code for rich text.
  • Coroutines are used to cleverly manage the main game loop.

Coroutines

  • A function that can suspend its execution (yield) until the given YieldInstruction finishes.
  • Normal coroutine updates are run after the Update() function returns.
  • Can be used as a way to spread an effect over a period time
  • It is also a useful optimization since it also allows you to determine at what rate any function gets called.

Return types & different uses of Coroutines:

yield                       // The coroutine will continue after all Update functions have been called on the next frame.
yield WaitForSeconds        // Continue after a specified time delay, after all Update functions have been called for the frame
yield WaitForFixedUpdate    // Continue after all FixedUpdate has been called on all scripts
yield WaitForEndOfFrame     // Continue after all FixedUpdate has been called on all scripts
yield WWW                   // Continue after a WWW download has completed.
yield StartCoroutine        // Chains the coroutine, and will wait for the MyFunc coroutine to complete first.

Coroutines also admit a nice, slick, readable game loop:

void Start() {
    // ... other start code ...
    StartCoroutine (GameLoop()); // Let's play!
}

// This is called from start and will run each phase of the game one after another.
private IEnumerator GameLoop() {
    yield return StartCoroutine (LevelStart()); // Start the level: Initialize, do some fun GUI stuff, ..., WaitForSeconds if setup too fast.
    yield return StartCoroutine (LevelPlay());  // Let the user(s) play the level until a win or game over condition is met, then return back here.
    yield return StartCoroutine (LevelEnd());   // Find out if some user(s) "won" the level or not. Also, do some cleanup.
    
    if (WinCondition) { // Check if game level progression conditions were met.
        Application.LoadLevel(++level); // or Application.LoadLevel(Application.loadedLevel) if using same scene
    } else { // Let the user retry the level by restarting this (non-yielding) coroutine again.
        StartCoroutine (GameLoop());
    }
}

08. Audio Mixing

Balance the audio in the game with a dynamic mix where sound effects duck the volume of the music.

  • A MainMix audio mixer default is created that outputs directly to the AudioListener.
  • Audio Mixer window is used to create 3 additional Audio Mixer Groups: Music, SFX, Driving.
    • Used to modify/mix the audio output before reaching the AudioListener.
  • Audio Source components (in our Prefabs) are setup to output their clips through the Audio Mixer Groups.
    • Default setup was to output clips straight to the AudioListener, without mixing.
  • A "Duck Volume" effect is then used to lower the bg music when sfx are playing.
    • The SFX group is setup to "Send Effect" its signal to the Music group's "Duck Volume" effect.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].