<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>unity Archives - SoftUni Global</title>
	<atom:link href="https://softuni.org/tag/unity/feed/" rel="self" type="application/rss+xml" />
	<link>https://softuni.org/tag/unity/</link>
	<description>Learn Programming and Start a Developer Job</description>
	<lastBuildDate>Thu, 31 Mar 2022 13:33:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://softuni.org/wp-content/uploads/2022/04/cropped-SoftUni-Global-Logo-Square-notext-32x32.png</url>
	<title>unity Archives - SoftUni Global</title>
	<link>https://softuni.org/tag/unity/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to Make Our Own Flappy Bird in Unity [Project Tutorials]</title>
		<link>https://softuni.org/project-tutorials/how-to-make-our-own-flappy-bird-in-unity/</link>
					<comments>https://softuni.org/project-tutorials/how-to-make-our-own-flappy-bird-in-unity/#respond</comments>
		
		<dc:creator><![CDATA[Aleksandar Peev]]></dc:creator>
		<pubDate>Tue, 08 Feb 2022 04:58:00 +0000</pubDate>
				<category><![CDATA[Step-by-Step Project Tutorials]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[flappy birds]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[step-by-step]]></category>
		<category><![CDATA[unity]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<guid isPermaLink="false">https://softuni.org/?p=11648</guid>

					<description><![CDATA[<p>In this article of the Project Tutorial series, we will create a simple Flappy Bird game, using Unity.</p>
<p>The post <a href="https://softuni.org/project-tutorials/how-to-make-our-own-flappy-bird-in-unity/">How to Make Our Own Flappy Bird in Unity [Project Tutorials]</a> appeared first on <a href="https://softuni.org">SoftUni Global</a>.</p>
]]></description>
										<content:encoded><![CDATA[		<div data-elementor-type="wp-post" data-elementor-id="11648" class="elementor elementor-11648" data-elementor-post-type="post">
						<section class="elementor-section elementor-top-section elementor-element elementor-element-5d5405e elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="5d5405e" data-element_type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-0d32134" data-id="0d32134" data-element_type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-9216798 elementor-widget elementor-widget-text-editor" data-id="9216798" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>In this demo, we will create our own Flappy Bird game using <strong>Unity</strong> and <strong>C#</strong>.</p><ul><li>Unity is, essentially, a well-rounded game engine that truly does simplify game development. While there may be better engines to choose from, learning Unity will only help you grow as a game developer.</li></ul><p>For this project, we are using the <strong>2020.3 LTS</strong> <strong>table release</strong>. To create this project you will need to have <strong>Unity</strong> and <strong>Unity Hub</strong> installed. You can <strong>download</strong> them from <a href="https://unity3d.com/get-unity/download">here</a>. To get the completed project, you can download it from the link below. (Link is available after successful registration)</p><ul><li><p>First, we open the <strong>Unity Hub</strong> and <strong>Create</strong> a <strong>2D Project</strong>.<img fetchpriority="high" decoding="async" class=" wp-image-11661 aligncenter" src="https://softuni.org/wp-content/uploads/2022/02/setup-path-300x160.png" alt="setup-path" width="677" height="361" srcset="https://softuni.org/wp-content/uploads/2022/02/setup-path-300x160.png 300w, https://softuni.org/wp-content/uploads/2022/02/setup-path-1024x545.png 1024w, https://softuni.org/wp-content/uploads/2022/02/setup-path-768x409.png 768w, https://softuni.org/wp-content/uploads/2022/02/setup-path-600x319.png 600w, https://softuni.org/wp-content/uploads/2022/02/setup-path.png 1101w" sizes="(max-width: 677px) 100vw, 677px" /></p></li><li><p>We create a <strong>Sprites</strong> folder in the game directory, and we import all the needed images for the game.</p></li><li>After we <strong>import</strong> the needed images, you can see that you have more than one bird. We slice it save it in a new folder called <strong>Animations</strong>.</li><li>We set it on the <strong>scheme</strong>, we can start the application and see if the bird will fall.</li><li>What we need to do next is create a script for our bird. We create a <strong>Bird.cs</strong> file in the Assets/Scripts folder. We <strong>create</strong> <strong>methods</strong> for the Bird to <strong>fly</strong> and <strong>set boundaries</strong> so it cannot fly outside our screen.</li></ul>								</div>
				</div>
				<div class="elementor-element elementor-element-6a49652 elementor-widget elementor-widget-code-highlight" data-id="6a49652" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-csharp line-numbers">
				<code readonly="true" class="language-csharp">
					<xmp>using System;
using UnityEngine;

public class Bird : MonoBehaviour
{
    [SerializeField] private Rigidbody2D _rigidbody;
    [SerializeField] private float _force;
    [SerializeField] private float _yBound;

    private void Update()
    {
        if (Input.GetMouseButtonDown(0) && _rigidbody.position.y < _yBound)
        {
            Flap();
        }
    }

    private void Flap()
    {
        _rigidbody.velocity = Vector2.zero;
        _rigidbody.AddForce(Vector2.up * _force);
    }
}
</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-411639f elementor-widget elementor-widget-text-editor" data-id="411639f" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<ul><li>Now we need to <strong>create</strong> pipes. We create <strong>Upper</strong> and <strong>Lower </strong>pipes. If the bird hits them the game will be over.</li><li>After we are done we create a <strong>MovingObject</strong> <strong>infinity</strong> <strong>runner</strong>. We need to <strong>constantly</strong> move the objects to the left. The speed <strong>increased</strong> by one, for every second that passes. We <strong>set boundaries</strong> for when the object is <strong>destroyed</strong>. We <strong>attach</strong> the script to the pipe. We can check if our scripts work.</li></ul>								</div>
				</div>
				<div class="elementor-element elementor-element-f4a4827 elementor-widget elementor-widget-code-highlight" data-id="f4a4827" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-csharp line-numbers">
				<code readonly="true" class="language-csharp">
					<xmp>using UnityEngine;

public class MovingObject : MonoBehaviour
{
    [SerializeField] private float _speed;
    [SerializeField] private float _xBound;

    private void Update()
    {
        this.transform.position -= Vector3.right * _speed * Time.deltaTime;

        if (this.transform.position.x < _xBound)
        {
            Destroy(this.gameObject);
        }
    }
}</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-b3697b2 elementor-widget elementor-widget-text-editor" data-id="b3697b2" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<ul><li>We can move to the <strong>spawner </strong>script. We create the <strong>class</strong> in the same scripts folder. We need a <strong>prefab</strong> to be <strong>spawned, </strong>and a time interval arrange by <strong>1 axis</strong> with a name &#8211; _yClamp. If enough time has <strong>elapsed</strong>, the object will <strong>spawn</strong>, and the <strong>elapsed</strong> time will <strong>reset</strong>.</li></ul>								</div>
				</div>
				<div class="elementor-element elementor-element-4b97940 elementor-widget elementor-widget-code-highlight" data-id="4b97940" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-csharp line-numbers">
				<code readonly="true" class="language-csharp">
					<xmp>using System;
using UnityEngine;

public class Spawner : MonoBehaviour
{
    [SerializeField] private GameObject _prefab;
    [SerializeField] private float _time;
    [SerializeField] private float _yClamp;

    private float _elapsedTime;

    private void Update()
    {
        _elapsedTime += Time.deltaTime;

        if (_elapsedTime > _time)
        {
            SpawnObject();

            _elapsedTime = 0f;
        }
    }

    private void SpawnObject()
    {
        float offsetY = UnityEngine.Random.Range(-_yClamp, _yClamp);

        Vector2 pos = new Vector2(this.transform.position.x, this.transform.position.y + offsetY);

        Instantiate(_prefab, pos, Quaternion.identity, this.transform);
    }
}
</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-138d7ce elementor-widget elementor-widget-text-editor" data-id="138d7ce" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<ul><li>After we are done we can put the <strong>spawner</strong> into action.  We create a <strong>spawner</strong> to spawn pipes, evey 2 seconds in the <strong>y-axis</strong>.</li><li>We add the functionality to the <strong>ground</strong> as well. If we hit play we can see the pipes and ground <strong>spawning infinitely</strong>.</li><li>In our next step, we need to make the game <strong>end</strong>. We add <strong>events</strong> to the Bird inside the Bird.cs class. As a <strong>bonus</strong> you can add sounds for different events. With <strong>OnCollisionEnter2D</strong>, our bird dies and we <strong>freeze</strong> the time.</li></ul>								</div>
				</div>
				<div class="elementor-element elementor-element-ecc7ef9 elementor-widget elementor-widget-code-highlight" data-id="ecc7ef9" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-csharp line-numbers">
				<code readonly="true" class="language-csharp">
					<xmp>    [SerializeField] private AudioSource _audioSource;
    [SerializeField] private AudioClip _flapSound;
    [SerializeField] private AudioClip _hitSound;
    [SerializeField] private AudioClip _scoreSound;
    public static event Action OnDeath;

    private void OnCollisionEnter2D()
    {
        OnDeath?.Invoke();

        _audioSource.PlayOneShot(_hitSound);

        Time.timeScale = 0f;
    }
    
    private void Start()
    {
        Time.timeScale = 1f;
    }
</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-550d174 elementor-widget elementor-widget-text-editor" data-id="550d174" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<ul><li><p>We need to <strong>create</strong> a button,  which starts our game.</p></li><li>We use the <strong>Observer</strong> <strong>Design</strong> <strong>Pattern</strong> and it&#8217;s commonly used in <strong>game development</strong>.</li><li><p>We create a new class called <strong>UIManager</strong>. In our class we add the following play button <strong>logic</strong>:</p></li></ul>								</div>
				</div>
				<div class="elementor-element elementor-element-7dbb766 elementor-widget elementor-widget-code-highlight" data-id="7dbb766" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-csharp line-numbers">
				<code readonly="true" class="language-csharp">
					<xmp>    [SerializeField] private GameObject _playButton;
    [SerializeField] private TMP_Text _score;

    private void Awake()
    {
        Bird.OnDeath += OnGameOver;
    }
    
    
    private void OnDestroy()
    {
        Bird.OnDeath -= OnGameOver;
    }

    public void RestartGame() => SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);

    private void OnGameOver() => _playButton.SetActive(true);

</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-b7f5a46 elementor-widget elementor-widget-text-editor" data-id="b7f5a46" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<ul><li><span data-preserver-spaces="true">What we need to do is create a <strong>text mesh</strong> for the score on our screen. In the Bird <strong>class</strong>, we add <strong>functionality</strong> so that the score will change. The <strong>OnTrigger</strong> event will <strong>trigger</strong> and <strong>play a sound</strong>.</span></li></ul>								</div>
				</div>
				<div class="elementor-element elementor-element-ee2595f elementor-widget elementor-widget-code-highlight" data-id="ee2595f" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-csharp line-numbers">
				<code readonly="true" class="language-csharp">
					<xmp>public static event Action OnScore;

    private void OnTriggerEnter2D()
    {
        OnScore?.Invoke();

        _audioSource.PlayOneShot(_scoreSound);
    }</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-473d62c elementor-widget elementor-widget-text-editor" data-id="473d62c" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<ul><li><span data-preserver-spaces="true">In the <strong>UI Manager</strong> we also need to add the <strong>functionality</strong> for the score. Each time the bird <strong>passes</strong> a pipe <strong>depending</strong> on the state we will get <strong>Awake()</strong> or <strong>OnDestroy()</strong> event. We <strong>increment</strong> the current number of the score when the score <strong>increases</strong>.</span></li></ul>								</div>
				</div>
				<div class="elementor-element elementor-element-886c880 elementor-widget elementor-widget-code-highlight" data-id="886c880" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-csharp line-numbers">
				<code readonly="true" class="language-csharp">
					<xmp>private void Awake()
{
    Bird.OnDeath += OnGameOver;
    Bird.OnScore += OnScore;
}
    
private void OnDestroy()
{
    Bird.OnDeath -= OnGameOver;
    Bird.OnScore -= OnScore;
}
private void OnScore() => _score.text = (int.Parse(_score.text) + 1).ToString();</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-b36e965 elementor-widget elementor-widget-text-editor" data-id="b36e965" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p><span data-preserver-spaces="true"><img decoding="async" class="aligncenter" src="https://softuni.org/wp-content/uploads/2022/02/final-look-177x300.png" alt="final-look-app" width="184" height="311" /></span></p><p><span data-preserver-spaces="true">If we followed all the steps as shown in the <strong>video tutorial</strong>, our project should be working. What you learned in this tutorial will work for most of your projects in any <strong>engine</strong>. <strong>Unity</strong>&#8216;s pipeline is smooth, yet complex. <strong>Unity</strong> is, simply put, the world’s most popular <strong>game engine</strong>. It packs a lot of features together and is flexible enough to make almost any game you can imagine. <strong>Unity</strong> packs tools for <strong>2D</strong> and <strong>3D</strong> game development.</span></p>								</div>
				</div>
				<div class="elementor-element elementor-element-88292b4 elementor-widget elementor-widget-video" data-id="88292b4" data-element_type="widget" data-settings="{&quot;youtube_url&quot;:&quot;https:\/\/youtu.be\/HQVUGyto8Gg&quot;,&quot;video_type&quot;:&quot;youtube&quot;,&quot;controls&quot;:&quot;yes&quot;}" data-widget_type="video.default">
				<div class="elementor-widget-container">
							<div class="elementor-wrapper elementor-open-inline">
			<div class="elementor-video"></div>		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-edfdd22 elementor-widget elementor-widget-text-editor" data-id="edfdd22" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<h2>Lesson Topics</h2><div><div><div>In this tutorial we cover the following steps:</div></div><ul><li><b style="font-style: inherit; color: var( --e-global-color-text );">Project Creation</b></li><li style="font-size: 15px;"><strong>Project Setup</strong></li><li style="font-size: 15px;"><strong>Creating a Bird</strong></li><li><strong>Adding the Bird Script </strong></li><li><strong>Prefabs</strong></li><li><strong>Adding Moving Object</strong></li><li><strong>Defining Spawner</strong></li><li><strong>Setup Spawners Usage</strong></li><li><strong>Implementing Game Over Feature</strong></li><li><strong>Adding Score</strong></li><li><strong>Adding SFX</strong></li><li><strong>Testing Project</strong></li></ul></div>								</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-dc263e9 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="dc263e9" data-element_type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-2f88ff6" data-id="2f88ff6" data-element_type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-96efd1f elementor-align-center elementor-widget elementor-widget-button" data-id="96efd1f" data-element_type="widget" data-widget_type="button.default">
				<div class="elementor-widget-container">
									<div class="elementor-button-wrapper">
					<a class="elementor-button elementor-button-link elementor-size-lg" href="https://github.com/origami99/Flappy-Bird-Demo" target="_blank">
						<span class="elementor-button-content-wrapper">
						<span class="elementor-button-icon">
				<svg aria-hidden="true" class="e-font-icon-svg e-fas-laptop-code" viewBox="0 0 640 512" xmlns="http://www.w3.org/2000/svg"><path d="M255.03 261.65c6.25 6.25 16.38 6.25 22.63 0l11.31-11.31c6.25-6.25 6.25-16.38 0-22.63L253.25 192l35.71-35.72c6.25-6.25 6.25-16.38 0-22.63l-11.31-11.31c-6.25-6.25-16.38-6.25-22.63 0l-58.34 58.34c-6.25 6.25-6.25 16.38 0 22.63l58.35 58.34zm96.01-11.3l11.31 11.31c6.25 6.25 16.38 6.25 22.63 0l58.34-58.34c6.25-6.25 6.25-16.38 0-22.63l-58.34-58.34c-6.25-6.25-16.38-6.25-22.63 0l-11.31 11.31c-6.25 6.25-6.25 16.38 0 22.63L386.75 192l-35.71 35.72c-6.25 6.25-6.25 16.38 0 22.63zM624 416H381.54c-.74 19.81-14.71 32-32.74 32H288c-18.69 0-33.02-17.47-32.77-32H16c-8.8 0-16 7.2-16 16v16c0 35.2 28.8 64 64 64h512c35.2 0 64-28.8 64-64v-16c0-8.8-7.2-16-16-16zM576 48c0-26.4-21.6-48-48-48H112C85.6 0 64 21.6 64 48v336h512V48zm-64 272H128V64h384v256z"></path></svg>			</span>
									<span class="elementor-button-text">Download Project</span>
					</span>
					</a>
				</div>
								</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-3cd15ec elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="3cd15ec" data-element_type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-56bfdb0" data-id="56bfdb0" data-element_type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
							</div>
		</div>
					</div>
		</section>
				</div>
		<p>The post <a href="https://softuni.org/project-tutorials/how-to-make-our-own-flappy-bird-in-unity/">How to Make Our Own Flappy Bird in Unity [Project Tutorials]</a> appeared first on <a href="https://softuni.org">SoftUni Global</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://softuni.org/project-tutorials/how-to-make-our-own-flappy-bird-in-unity/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Lazy Loading (feed)

Served from: softuni.org @ 2026-06-06 07:28:08 by W3 Total Cache
-->