<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Dustin Cargile on Medium]]></title>
        <description><![CDATA[Stories by Dustin Cargile on Medium]]></description>
        <link>https://medium.com/@dcargile84?source=rss-dd67903bab0d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*EqrQlX0LnlRv1uc2g7Jw6w.png</url>
            <title>Stories by Dustin Cargile on Medium</title>
            <link>https://medium.com/@dcargile84?source=rss-dd67903bab0d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 00:17:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dcargile84/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Create a Loading Bar in Unity]]></title>
            <link>https://medium.com/@dcargile84/create-a-loading-bar-in-unity-682eaf56d600?source=rss-dd67903bab0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/682eaf56d600</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[game-design]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[made-with-unity]]></category>
            <dc:creator><![CDATA[Dustin Cargile]]></dc:creator>
            <pubDate>Fri, 19 Apr 2024 05:11:20 GMT</pubDate>
            <atom:updated>2024-04-19T05:11:20.712Z</atom:updated>
            <content:encoded><![CDATA[<p>Thanks to <a href="https://medium.com/@dcargile84/build-an-amazing-health-bar-in-unity-227149b3ec7b">the previous article</a>, we have a fair grasp of applications for a <strong>Slider</strong>. We built a health bar that can give a visual representation of a health variable. We can further adapt this for another application, a <strong>Loading Bar</strong>. Loading bars are used in just about every type of program in existence.</p><p>Making one is surprisingly simple. First, we start with our <strong>Scene</strong>. We have a <strong>Canvas </strong>with a <strong>Slider </strong>and some <strong>Text </strong>to give a numerical value to our progress.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*PIJY7ywdx2jyEWxv6vAmQw.png" /></figure><p>We also have a second <strong>Scene </strong>that we will load up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/163/1*YUGGzEqjEJTtY-Qp8iaEXw.png" /></figure><p>We will need to access <strong>Asynchronous Loading</strong>. If we look at the documentation for this process, we get a coding snippet that we can pretty much copy and paste into our code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BwHCnGahc5wpBHZqdzwJ5w.png" /></figure><p>The documentation states that we will have to access the <strong>SceneManagement Library </strong>so we will add that to our usual <strong>Namespaces</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*bwHGgzBfIsRFE3GoYu_hKw.png" /></figure><p>We will need a few variables: a <strong>Float </strong>to store the value of a progress percentage and references to the <strong>Slider </strong>and <strong>Text </strong>for our loading bar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/1*5DC97dU05S_KumHczG6ZSA.png" /></figure><p>The documentation shows us an <strong>IEnumerator </strong>in which we will create an <strong>AsyncOperation </strong>that will load our next Scene asynchronously. During the loading process, the <strong>AsyncOperation </strong>will keep track of our progress, which we can access and store in our <strong>Float</strong>. We will also make another method that will take our progress and <strong>Update </strong>the <strong>Slider </strong>and <strong>Text</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*gF7BOZGVPcK3ZKyFafSqAw.png" /></figure><p>The value returned by the progress will be between <strong>0 </strong>and <strong>1</strong>. For our display text, we will turn that value into a whole number percentage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*cYDE20jDxg7FEg_heznPJA.png" /></figure><p>We will start the <strong>IEnumerator </strong>when we press the <strong>Space </strong>key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*X_j2UMvL-nOYR95Kx-pf2w.png" /></figure><p>Finally, we will also call the <strong>UpdateLoadingBar </strong>method at <strong>Start </strong>in order to properly display the <strong>Slider </strong>and <strong>Text</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/239/1*jM-DbaeUa4Ci21XCylXsUQ.png" /></figure><p>Now, we load in all our fields.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/332/1*TGXKQaOp_gQad3KdfczRvQ.png" /></figure><p>Anytime we are dealing with <strong>SceneManagement</strong>, it is a good idea to make sure that all <strong>Scenes </strong>involved are in the <strong>Scene </strong>In <strong>Build </strong>section of the <strong>Build Settings</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/158/1*n1xW3vj9GOkDmQayrpyiiA.png" /></figure><p>Now, we run the application and press the <strong>Space </strong>key. It goes by super quick since the second <strong>Scene </strong>is really just a couple of <strong>Images</strong>, but we see just a flash of the <strong>Loading </strong>Bar filling to <strong>90% </strong>and then loading the next <strong>Scene</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*sMlPyxBhpdXFtBZ56vhAIg.gif" /></figure><p>It’s not super exciting but it is an imperative part of application creation. The feedback from a loading bar tells the user that the application is in the process of completing a task, which says: “Hey! I’m doing something. I’m still working. Please don’t do anything until I’m done.”</p><p>There you go, a simple and easy solution to one of the most common components in software engineering.</p><p>Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=682eaf56d600" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build an Amazing Health Bar in Unity]]></title>
            <link>https://medium.com/@dcargile84/build-an-amazing-health-bar-in-unity-227149b3ec7b?source=rss-dd67903bab0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/227149b3ec7b</guid>
            <category><![CDATA[game-design]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[made-with-unity]]></category>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Dustin Cargile]]></dc:creator>
            <pubDate>Fri, 19 Apr 2024 01:37:20 GMT</pubDate>
            <atom:updated>2024-04-19T01:37:20.199Z</atom:updated>
            <content:encoded><![CDATA[<p>I have already talked a bit about how to make a health bar from scratch back <a href="https://medium.com/@dcargile84/designing-a-boss-bonus-creating-a-health-bar-87a8a1e87bfb">in this article</a> way back from the <strong>2D Space Shooter</strong> series. There is an easier way to make this system though. We can use <strong>Unity’s </strong>built-in <strong>Slider </strong>to make a health in just a few steps.</p><p>We start with a simple <strong>Slider Object </strong>that contains a few other objects. One thing that we added is the <strong>Text </strong>to the <strong>Handle </strong>so that we have <strong>Text </strong>that will move along as the <strong>Slider Value </strong>changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*3TGTT8mN6MXm9Fu-nup0RA.png" /></figure><p>The <strong>Slider </strong>by itself looks like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*4PwtMuNGoHWjxVh5ztDRlA.png" /></figure><p>We have a few things that we can customize to our liking. The <strong>MaxValue </strong>is <strong>Defaulted </strong>at <strong>1</strong> but we can change it to anything we like. We can also adjust the <strong>Slider </strong>to only use <strong>Whole</strong> <strong>Numbers </strong>for its values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/323/1*KSppVbRVrt6dAlbPjdiWUA.png" /></figure><p>The <strong>Handle </strong>is generally the object that <strong>User </strong>will interact with. Since we are making a health bar, we don’t actually need this <strong>Object</strong>. We can first turn off the <strong>Interactable </strong>option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*iNgqKmBvjwhfo7NluBTMXQ.gif" /></figure><p>We can then disable the <strong>Handle’s Image </strong>so that it is still there but we can’t see or interact with it. We can use its location to move our <strong>Text </strong>though.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*mcRkH8rhSnt-hPvXP3LmmQ.png" /></figure><p>As we can see there is a bit of the <strong>Fill </strong>that is still visible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*7s7oE7N1IK2CuqzVwYUdKg.png" /></figure><p>We can fix this by setting the <strong>Fill’s</strong> <strong>Width </strong>to <strong>0</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/1*KcI6TCUHYnpQODVy1l9wrw.gif" /></figure><p>We can also adjust the <strong>Color </strong>of the <strong>Fill</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/1*Llz7UD5q2lJ8v2OfC3yNVQ.gif" /></figure><p>Likewise, we can adjust the <strong>Color </strong>of the <strong>Background’s Image Component</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/326/1*ghyV5kLNrsjV7jqt3gISBg.gif" /></figure><p>This results in an amazing-looking health bar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*OzoJg9B35dgCqeVmWRQ0uw.gif" /></figure><p>Now, we move on to the coding. As always we start with adding our <strong>Namespaces </strong>for any <strong>Libraries </strong>we need access to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/195/1*9MHGOS6trylqZgib0aRDMw.png" /></figure><p>We now add our variables for our <strong>Slider </strong>and the <strong>Text </strong>attached to the <strong>Handle</strong>. We will also keep track of our health with <strong>Floats </strong>for the current and maximum health values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*melaX5o8MI_4zX8nQsYcfg.png" /></figure><p>Now, we need to <strong>Initialize </strong>our beginning values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/1*fR3PXd0btM-ucOdaMcNCvA.png" /></figure><p>Then, we create methods for taking damage and healing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*YOmJ9kyVHa4umG1TSNHMcA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/311/1*7zCl1VO5rFmR6ZSI15nZqw.png" /></figure><p>We will also create a method to take <strong>Input </strong>from the keyboard to determine if we are taking damage or healing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*bVRN0Kx-jMNuCbXOuRGpfw.png" /></figure><p>Lastly, we will update our <strong>Slider </strong>and <strong>Text </strong>to the current health.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*AvIs1vmaMkrmtBNl5UM_Cg.png" /></figure><p>We will call the <strong>CalculateControls</strong> and <strong>UpdateSlider </strong>methods during the <strong>Update </strong>method for testing purposes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/251/1*klC-GJ_c9zBg4-Wvara7pw.png" /></figure><p>Now if we run the <strong>Application</strong>, the <strong>Slider </strong>moves down when we take damage and vice-versa when we heal. The <strong>Text </strong>also <strong>Updates </strong>according to the current health. So, it looks like it is all working as intended.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*lMWw6Dl4tFnJsVVuwH1CsQ.gif" /></figure><p>Now, we can make some adjustments and refactor a bit. For instance, we can put the <strong>UpdateSlider </strong>method call into the <strong>TakeDamage</strong>, <strong>Heal</strong>, and <strong>Start </strong>methods. This will only call the <strong>UpdateSlider </strong>method when the <strong>Value </strong>is changed as opposed to every <strong>Update</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/321/1*ugczVljwOVmzwQj9NqNoKw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*vWaTuflrUyQVyDS8zwNObA.png" /></figure><p>We can also add a reference to the <strong>Fill’s Image Component</strong>. We will also add a <strong>Gradient Field</strong>. We will use this to adjust the <strong>Color </strong>of the <strong>Fill </strong>depending on the <strong>Slider’s Value</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*9ZF1qLaEa-rNpIdRnedzSw.png" /></figure><p>Now, we will make a method to change the <strong>Color </strong>value of the <strong>Fill</strong>. We will get the current health divided by the maximum health to get a <strong>Float </strong>value between <strong>0 </strong>and <strong>1</strong>. We then use that number to determine a point along the <strong>Gradient </strong>and get a <strong>Color</strong>. Then, we simply adjust the <strong>Fill Image’s Color </strong>to that <strong>Color</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*k5cCYTo1vrghOwIDV8Y_FQ.png" /></figure><p>Now, we add the <strong>UpdateColor </strong>method to the <strong>UpdateSlider </strong>method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*zxRqcG8sky328QUhy0ljrQ.png" /></figure><p>Now, we need to make a <strong>Gradient</strong>, which we can do simply by clicking on the field in the <strong>Inspector </strong>and adjusting values to our liking.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*Xx-srdmLK3tjDJ0ceq_DaA.png" /></figure><p>We can also change the <strong>Background’s Color </strong>to <strong>Black</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/1*4VHnJ04nY30QeLX0AXDKzw.gif" /></figure><p>Now, when we run the application and change values, our health bar will change colors based on the current health.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*klFxVemg6bLsWwtJLRdzGA.gif" /></figure><p>There are of course multiple other things that we can do to improve upon this setup. For now, we have a basic, working health bar we can incorporate into almost any game.</p><p>Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=227149b3ec7b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making a Fun Slideshow Using Toggle Buttons]]></title>
            <link>https://medium.com/@dcargile84/making-a-fun-slideshow-using-toggle-buttons-a9aca2642f40?source=rss-dd67903bab0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9aca2642f40</guid>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[game-design]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[made-with-unity]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Dustin Cargile]]></dc:creator>
            <pubDate>Wed, 17 Apr 2024 04:04:29 GMT</pubDate>
            <atom:updated>2024-04-17T04:04:29.079Z</atom:updated>
            <content:encoded><![CDATA[<p>Using what we learned in<a href="https://medium.com/@dcargile84/creating-a-difficulty-system-toggle-switch-b2a71f2f5576"> the previous article</a>, we can dive a bit deeper into coding our <strong>Toggle Buttons </strong>to actually change things within our game or application. In this case, we want to create a <strong>Toggle Group </strong>that will display a different picture depending on which <strong>Toggle </strong>is selected. This does require a few things to get started.</p><p>We can start with the <strong>Image </strong>that we will use. This <strong>Image </strong>is a collage of 4 <strong>Images </strong>stuck together. We will need to separate them to use them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*ro8NnQMoGoC6LPDHD5A3-g.jpeg" /></figure><p>Luckily, <strong>Unity </strong>makes it fairly easy to split an <strong>Image </strong>into <strong>Multiple Sprites</strong>. When we are defining the <strong>Texture Type </strong>of the imported <strong>Image</strong>, the <strong>Sprite </strong>option also allows us to define a <strong>Sprite Mode</strong>. If we select <strong>Multiple</strong>, we can then Slice the Image within the <strong>Sprite Editor</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/308/1*dGKAEtAskc_-GT6LMGvKLQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/308/1*4-Ajm6O74FIBSbauSU6Evg.png" /></figure><p>When we select the <strong>Slice </strong>option we can also select the <strong>Grid By Cell Size</strong> <strong>Type </strong>and give parameters to set the size of each cell. In this case, the <strong>Image </strong>is <strong>300 x 300</strong>. To separate it into quadrants, we make each cell <strong>150 x 150</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/347/1*tSarlc-4NEujY3uJsMAWEQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*XM1WCmi1fyvDMXCCYoGHiQ.png" /></figure><p>Now, we just set up our <strong>UI </strong>to include an Image and some <strong>Toggles</strong>. We also can include some <strong>Text </strong>that will change for each <strong>Image</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*XSeBhvYCpIIJKtA69YhJDw.png" /></figure><p>To control everything, we need to make a <strong>Manager</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/222/1*fkmW_Dq9gubr4GxDAVCcjg.png" /></figure><p>Within that <strong>Manager’s Script</strong>, we will include the appropriate <strong>Namespaces</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/210/1*bWQofs9jq3XcbOKT8ERKDg.png" /></figure><p>We organize everything neatly into <strong>Arrays</strong>. We need an <strong>Array </strong>for the <strong>Toggles</strong>, the <strong>Sprite Images</strong>, and the messages that will be displayed. We will also need to reference the <strong>Image </strong>that will hold the <strong>Sprites </strong>and the <strong>Text </strong>that will display our messages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/1*HtAC1Dn-vt_qrlsYMFPFSA.png" /></figure><p>Since everything is in <strong>Arrays </strong>we can simply pass an integer into our method to reference each item in each <strong>Array</strong>. Basically, if we have the first <strong>Toggle </strong>selected, then the first <strong>Sprite </strong>and the first message will be displayed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*Sjw_X8MGVmYeHj5kc3Drzw.png" /></figure><p>This setup also allows us to use a <strong>For Loop </strong>at <strong>Start </strong>to ensure the appropriate <strong>Sprite </strong>and message are displayed upon startup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*n0J8ANyA13G5uwU2A22vyQ.png" /></figure><p>Now, all we have left is to load up the <strong>Manager </strong>with all of the necessary <strong>Objects </strong>and <strong>Assets</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/333/1*tTqqRWDB2jZNcOCbd5n6WA.png" /></figure><p>Now, when we run the application, we have a fun slideshow that switches between Images based on the selected <strong>Toggle</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*UrnpM1mtY6q-HApZ92PW8Q.gif" /></figure><p>Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9aca2642f40" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Difficulty System Toggle Switch]]></title>
            <link>https://medium.com/@dcargile84/creating-a-difficulty-system-toggle-switch-b2a71f2f5576?source=rss-dd67903bab0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2a71f2f5576</guid>
            <category><![CDATA[made-with-unity]]></category>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[game-design]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Dustin Cargile]]></dc:creator>
            <pubDate>Tue, 16 Apr 2024 19:28:30 GMT</pubDate>
            <atom:updated>2024-04-16T19:28:30.092Z</atom:updated>
            <content:encoded><![CDATA[<p>We are going to make a difficulty selection system using <strong>Toggles</strong>. What the heck is a <strong>Toggle </strong>though? Simply put a <strong>Toggle </strong>is a sort of <strong>Button </strong>that exists in one of two states: either <strong>true </strong>or <strong>false </strong>or, simpler still, <strong>on</strong> or <strong>off</strong>. It consists of several objects nested together. The <strong>Parent Object </strong>contains the <strong>Toggle Component</strong>. The <strong>Background </strong>and <strong>Checkmark </strong>are Images that show the state of the <strong>Toggle</strong>. Of course, the <strong>Label </strong>gives a concise description of the <strong>Toggle</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/179/1*pkj3srFRvZ_pBEpWiNm-VA.png" /></figure><p>In an application, the <strong>Toggle </strong>will switch between <strong>On </strong>or <strong>Off </strong>states when clicked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*h1OEkGE-y1bQugoioZy84Q.gif" /></figure><p>Each of the items that make the <strong>Toggle </strong>can be customized with custom <strong>Fonts </strong>and <strong>Images</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/173/1*lwZtOVwhb53Qm5s1LzX4nA.png" /></figure><p>Now, with the explanations out of the way, we can make our difficulty selector. We start with one <strong>Toggle </strong>and apply any customization to it. Then, we will duplicate this <strong>Toggle</strong>, one for each difficulty we want to display.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/179/1*KlRT_fp1XKWNdib8jBhgRw.gif" /></figure><p>We make sure to name these to avoid confusion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/187/1*4q0ph77A4MRUVsuryepiqQ.png" /></figure><p>Then space them out and edit the <strong>Label </strong>to better describe the <strong>Toggle</strong>, in this case, which difficulty the <strong>Toggle</strong> is associated with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*6ZSrKZxr4J6JPSIaCcDOGg.png" /></figure><p>Now, we will <strong>Right-Click </strong>on the <strong>Panel </strong>and select <strong>Create Empty </strong>to create a new <strong>Empty Object</strong>. This will serve as our <strong>Toggle Group</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/302/1*kD2j1GE2I6PCNIe5w1hprg.gif" /></figure><p>We then select all 3 Toggles and drag them onto the <strong>Toggle Group </strong>making them a <strong>Child </strong>of the <strong>Toggle Group</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/302/1*PexabK6U7WmMeFmVqUd09A.gif" /></figure><p>Now, with the <strong>Toggle Group </strong>selected, we will click <strong>Add Component </strong>and search for <strong>Toggle Group</strong>. Simply click <strong>Toggle Group </strong>to add the <strong>Component </strong>to the <strong>Object</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*X6bLAnFa7O0Gqkl-i3wmiA.gif" /></figure><p>On each <strong>Toggle</strong>, we will have to drag the <strong>ToggleGroup Object </strong>into the <strong>Group </strong>parameter located within each <strong>Toggle’s Toggle Component</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*r2M7l-uSJjXTUC0KKMisXg.gif" /></figure><p>Immediately, when we run the application, we can see the <strong>Toggle Group </strong>in action. Each object is communicating with each other and will turn itself off if a different <strong>Toggle </strong>within the <strong>Group </strong>is turned on. This allows us to limit <strong>Player </strong>selections to only one, as such would be the case for difficulty selection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*jnMPX0xseTgM1R09gp9KYQ.gif" /></figure><p>Now, we can get into the coding portion of this. We can create a new <strong>Empty Parent </strong>for the <strong>Canvas </strong>and a new <strong>Empty Object </strong>under that <strong>Parent </strong>to act as our <strong>DifficultyManager</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/197/1*RfYJVEoy-YxC9MgLVOMVyg.png" /></figure><p>We can attach a new <strong>Script </strong>to the <strong>Difficulty Manager</strong>. Within this <strong>Script</strong>, we will need to add the <strong>UnityEngine.UI </strong>and <strong>TMPro </strong>namespaces, giving us access to those <strong>Libraries</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/205/1*0Ttm5m_NBe1ZyK4vd7tYvw.png" /></figure><p>We only need two <strong>Fields</strong>. One <strong>Field </strong>is an Array of our Toggles and the other will be our display text that we will have as a <strong>TextMeshPro Object</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*-oMclDuxTxrYKN9u2FvcpA.png" /></figure><p>Next, we will create the <strong>Methods</strong>. We will create a <strong>Method </strong>for each difficulty. Basically, these <strong>Methods </strong>will check if the <strong>Toggle </strong>within the <strong>Array </strong>at its specific location is turned on. If the <strong>Toggle </strong>is turned on, it will change the display text accordingly. In this case, we want the <strong>Easy Toggle</strong> to be at location <strong>0 </strong>on the <strong>Array </strong>and if that <strong>Toggle </strong>is on, then we will display <strong>“Easy”</strong> on the display text.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/315/1*rIssktQjgsg2ivt0IhvfgQ.png" /></figure><p>Now, to assign these objects, we can select the <strong>DifficultyManager </strong>and click the Lock icon in the<strong> Top-Right</strong> of the <strong>Inspector</strong>. This will keep the <strong>DifficultyManager </strong>displayed in the <strong>Inspector </strong>even if we select a different <strong>Object</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/1*t7ZxUYymKPAkrQ2EndexeQ.gif" /></figure><p>Now, we will select all 3 <strong>Toggles </strong>and drag them onto the <strong>Toggle </strong>parameter in the <strong>Inspector</strong>. We can expand the <strong>Array </strong>within the <strong>Inspector </strong>to confirm the <strong>Toggles </strong>are in their preferred positions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*Q2Mv6CbpAfdTxMRTr-MBVw.gif" /></figure><p>Lastly, after we add the display text <strong>Object</strong>, we can add it to the <strong>DifficultyManager </strong>as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*Bel9A7FmCEOSfxGSlnIRGA.gif" /></figure><p>Now, for each <strong>Toggle</strong>, we will click the <strong>plus sign</strong> on the <strong>On Value Changed</strong> section, drag the <strong>DifficultyManager </strong>into the <strong>GameObject Parameter</strong>, and find the <strong>Method </strong>associated with the <strong>Toggle </strong>within the <strong>DifficultyManager </strong>using the <strong>Function Selection Dropdown</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/309/1*rZFepqXIYm2iHVHhPuuagw.gif" /></figure><p>Another bit of code that we can add to the <strong>DifficultyManager </strong>is to run each of our custom <strong>Methods </strong>at <strong>Start </strong>so that our display text will be accurate from the get-go.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/463/1*WD47x84xoztVgaRQ-QPULQ.png" /></figure><p>Now, we run the application. We can see that we can select each difficulty, only one can be selected at a time, and the display text displays the selected difficulty accurately.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*eIxoUEJWHUXz0t83kRUN5Q.gif" /></figure><p>Now, we have a difficulty selector that our <strong>Players </strong>can use in almost any game, except Elden Ring or anything made by From Software.</p><p>Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2a71f2f5576" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Operate a Cannon Using UI Buttons in Unity]]></title>
            <link>https://medium.com/@dcargile84/operate-a-cannon-using-ui-buttons-in-unity-7741640522cc?source=rss-dd67903bab0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/7741640522cc</guid>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[game-design]]></category>
            <category><![CDATA[made-with-unity]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Dustin Cargile]]></dc:creator>
            <pubDate>Mon, 15 Apr 2024 18:34:28 GMT</pubDate>
            <atom:updated>2024-04-15T18:34:28.359Z</atom:updated>
            <content:encoded><![CDATA[<p>A common practical use of <strong>UI </strong>is to manipulate in-game objects with the <strong>UI</strong>. This is especially present in mobile games where the game controller is an on-screen <strong>UI </strong>that the <strong>Player </strong>uses to move around and interact with the world. This process is as easy as any other Button setup that we have used before.</p><p>First, we start with a cannon that can already tilt the cannon, turn left or right, and fire a cannonball. All of these controls are currently carried out by use of a keyboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*JnCSShTDAt9ZhTlxVIodjg.gif" /></figure><p>We can add our <strong>Canvas </strong>to the <strong>Scene </strong>and set it to <strong>Scale With Screen Size</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/1*AWtXoKN8K42mGblKF0b8Uw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*dJqzg2fkiCZ9ZZOxyTfrIw.png" /></figure><p>Now, we can add a <strong>Button</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*30uRMbx_mXdpa8oCr4VHeA.png" /></figure><p>We can delete the <strong>Text </strong>component from this one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/282/1*ATBZm_Hyga5Mj_Jun2YRxA.gif" /></figure><p>We can also change the <strong>Sprite </strong>to something a bit more fun.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*voDPinLH-ro24mZb0aexwA.png" /></figure><p>We can add an <strong>Image </strong>of an arrow to represent our directions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/228/1*Wy5AEHPYaM3PklrJar-iPQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/171/1*YZxYY4dqVxJqKQvmbNTkIw.png" /></figure><p>We need to make sure to disable the <strong>Raycast Target </strong>on the <strong>Image. </strong>If we do not, anytime we click within the boundaries of the <strong>Image</strong>, the <strong>Button </strong>will not be pressed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/277/1*fiGG0E3ZFMswGhNctZxkNw.gif" /></figure><p>Now, we just duplicate the button and rotate the <strong>Arrow </strong>Image to form our 4 directions:<strong> Up, Down, Left, and Right</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*H1xcVHiM9zbu6CU5dJ9mEg.gif" /></figure><p>Our UI is almost ready with all 4 direction <strong>Buttons </strong>created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*umU1ZjKntXS3z9iOMcfiTg.png" /></figure><p>Don’t forget to <strong>Name </strong>your <strong>Objects </strong>in the <strong>Hierarchy</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/190/1*a2n7EjXvZrWW6TWvkTIEJQ.png" /></figure><p>Lastly, for the design, we will add a fire <strong>Button</strong>. This is just a regular <strong>Text Mesh Pro Button </strong>with the same <strong>Sprite </strong>as the other <strong>Buttons</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*E2qb60fw-yp4ctdjKiYX_g.png" /></figure><p>Now, in the <strong>Code</strong>, we already have all of the methods that we need and they are all set to public. This means that we can access them with the Buttons.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JWKC5gguzDDocGH-LaWKZg.png" /></figure><p>On each <strong>Button</strong>, we will click the plus sign to add an <strong>OnClick Event </strong>to the <strong>Button</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/321/1*xVDzVKXOBk979UTCVx9CKw.gif" /></figure><p>We will drag the object the contains the <strong>Script </strong>that controls our cannon into the <strong>OnClick’s </strong>object slot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*AqjAh9OOlWgtBMtr4bthUw.gif" /></figure><p>Then, we can select <strong>Functions </strong>associated with that object. We will repeat this process for each of the Buttons assigning the appropriate method to each <strong>OnClick Event</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/313/1*e9MiXXk6ykXo2Z1Isi1Z-g.gif" /></figure><p>When we are done, we can now control our cannon easily with the on-screen <strong>UI</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*xIorOLLCvhncFpiVLn0Fuw.gif" /></figure><p>Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7741640522cc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use buttons in Unity with and without a mouse]]></title>
            <link>https://medium.com/@dcargile84/how-to-use-buttons-in-unity-with-and-without-a-mouse-19cf66984222?source=rss-dd67903bab0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/19cf66984222</guid>
            <category><![CDATA[game-design]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[made-with-unity]]></category>
            <dc:creator><![CDATA[Dustin Cargile]]></dc:creator>
            <pubDate>Sat, 13 Apr 2024 21:36:53 GMT</pubDate>
            <atom:updated>2024-04-13T21:36:53.681Z</atom:updated>
            <content:encoded><![CDATA[<p>Sometimes when interacting with our applications, a mouse is not an available option, albeit on very rare occasions. More commonly we can allow a more efficient navigation experience by allowing just a keyboard to be used. Either way, we as designers and developers can anticipate and prepare for these scenarios. Unity comes with some built-in options that help us to make easily customizable interfaces that accept input from a keyboard or console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*N2hZ5Zhzt1idJlnt9P1zOA.png" /></figure><p>We have this mock menu setup to illustrate how we can use the keyboard to navigate. There are some animations on the buttons but are otherwise normal Unity buttons. When we select the button and scroll to the Navigation section, that is where the magic happens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/269/1*H5blIinB59ORnPq9LkWVxQ.png" /></figure><p>If we select just the Explicit option, we have complete control over which button is selected based on the Up, Down, Left, and Right Arrow Keys. All we have to do is drag the object from our Hierarchy to the appropriate slot in the Inspector.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/273/1*8iO0VZhRaReitpSK9uIddA.png" /></figure><p>In this case, we will navigate to the next button when we press the Down Arrow and will navigate to the last button when we press the Up Arrow. This allows us to loop through the menu with just the keyboard once we assign the other buttons accordingly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/1*D6DFsaQfFiWR9uO2Ri3TWQ.gif" /></figure><p>We can also click the Visualize button so that we can see the Navigation flow. This can be helpful for more complex or confusing setups.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/424/1*-ZhSWVsqlfHrnAvejaDzzA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*FHfAnQGgWPjZvPqFiT0P8g.png" /></figure><p>And that’s how we can set up button navigation with just a few button clicks and some drag and drop.</p><p>Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19cf66984222" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I Made a Virtual Piano in Unity]]></title>
            <link>https://medium.com/@dcargile84/how-i-made-a-virtual-piano-in-unity-66c8464de013?source=rss-dd67903bab0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/66c8464de013</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[made-with-unity]]></category>
            <category><![CDATA[game-design]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Dustin Cargile]]></dc:creator>
            <pubDate>Fri, 05 Apr 2024 06:34:33 GMT</pubDate>
            <atom:updated>2024-04-05T06:34:33.387Z</atom:updated>
            <content:encoded><![CDATA[<p>We have been learning about some awesome concepts regarding <strong>Unity’s</strong> <strong>UI System</strong>. We’ve learned how to make a <strong>Minimap </strong>and <strong>Main Menu</strong> and learned about <strong>Images</strong>, <strong>Buttons</strong>, and other <strong>UI Elements</strong>. It’s time that we actually make something with this knowledge. Let’s make a virtual piano.</p><p>To start off, we’ll need a background and a <strong>Button</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*O-ReCffCbwpnQGVvBtYE6Q.png" /></figure><p>We don’t need the <strong>Text </strong>for the <strong>Button</strong>. So, we’ll delete it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/191/1*ja-VBybZljBtGg4ijLyngg.gif" /></figure><p>Next, we’ll swap the <strong>Height </strong>and <strong>Width </strong>of the <strong>Button </strong>so that it is long and skinny like a piano key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/267/1*mSYnWN6d8y73_ridCp2nkA.gif" /></figure><p>Just like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*I6flEokNNJTnrImn9ACaKg.png" /></figure><p>Now, we’ll create a new <strong>Script </strong>to handle our logic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/287/1*l3a4uqLkM3pO9JUzZYeDqQ.gif" /></figure><p>In that <strong>Script</strong>, we need to add the <strong>UI Namespace</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/1*q5BjQlJ0tQ1_UsXz3VQAFQ.png" /></figure><p>We also need some variables. One for the clip that we are playing, where we are playing it, and a <strong>Float </strong>value that we can tweak the notes pitch with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*c_eZslrunHpSc2otvjxCRQ.png" /></figure><p>Of course, we need a method to call when we press the <strong>Button</strong>. This method will adjust the <strong>Pitch </strong>of the <strong>Audio</strong> <strong>Source </strong>according to the <strong>Float </strong>value we set on the <strong>Button</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*F4o6jWZ7QCex6GwdmYeZGQ.png" /></figure><p>Now, we add the <strong>Script </strong>to our <strong>Button</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*z6f-yst4Cjo-F3SBFyY9SA.gif" /></figure><p>We assign the <strong>Audio</strong> <strong>Clip </strong>to the <strong>Audio Clip </strong>field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*uPyKbXryWMiywqvPTma78A.gif" /></figure><p>Next, we add an <strong>Audio Source </strong>and assign it to the <strong>Audio Source </strong>field as well as adjust the <strong>Pitch </strong>to the preferred default value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/1*waI4ncPWb4BbAZ_H8w2RiQ.gif" /></figure><p>Our <strong>Audio Source </strong>wants an <strong>Audio Mixer </strong>so we’ll add one to our <strong>Assets</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*8MticvbZW690002cZ7Yi6Q.png" /></figure><p>We can double-click on the <strong>Audio Mixer </strong>to open its own tab. From here, we can click the plus button on the <strong>Groups </strong>to add our own <strong>Group</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*ZlRrDr9GB8sPuoFNfTgBdQ.gif" /></figure><p>And now we add the <strong>Audio Mixer Group </strong>to the <strong>Output </strong>field of our <strong>Button’s Audio Source Component</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/282/1*AoAliqcfdelW97oanoiLOQ.gif" /></figure><p>With all of that out of the way, <em>whew, </em>we can now add an <strong>OnClick Event</strong> to our <strong>Button</strong>. We add the <strong>Script </strong>to the <strong>OnClick </strong>Event and then find the <strong>ButtonPressed Function </strong>we made earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*EztmVaIUQp_ZIUmTXvWoxg.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*_xEMHwlB5g4ySYK3Cfomhw.png" /></figure><p>We can test now and we should get some sound out of the <strong>Button </strong>when we press it. Now, we can duplicate the <strong>Button </strong>several times to make a set of keys.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*VEO-4wG3uKAeaN7chkLtpQ.png" /></figure><p>We then adjust the <strong>Pitch </strong>for each <strong>Button </strong>to get a different note.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/276/1*kQ5T5tAxhb8j0BFbQQqbqQ.gif" /></figure><p>And now we have a mini virtual piano.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*Hr6goZniNbCB0t1XJ0HETg.gif" /></figure><p>And with just a bit more work you can make it even better.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*w8qUY0U_sIKFZk4jAL_Tow.png" /></figure><p>Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=66c8464de013" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a Main Menu in Unity]]></title>
            <link>https://medium.com/@dcargile84/build-a-main-menu-in-unity-624daf26bb59?source=rss-dd67903bab0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/624daf26bb59</guid>
            <category><![CDATA[made-with-unity]]></category>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[game-design]]></category>
            <dc:creator><![CDATA[Dustin Cargile]]></dc:creator>
            <pubDate>Fri, 05 Apr 2024 03:45:17 GMT</pubDate>
            <atom:updated>2024-04-05T03:45:17.468Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*u0eTjjCAdlB6xgpPmB-Omg.png" /></figure><p>One of the most important parts of any game is the <strong>Main Menu</strong>. Some menus are simple and let the <strong>Players </strong>jump into the game quickly without any hassle and some are rather more complex, giving a glimpse into the overall idea of the game. Any way that we decide to go about making our <strong>Main Menu</strong>, there are a few basics that we can cover that will work in any case.</p><p>First, we add a <strong>Canvas</strong>. We want our <strong>Canvas </strong>to be compatible with any screen resolution so we set the <strong>UI Scale Mode</strong> to <strong>Scale With Screen Size</strong>. We can also change the <strong>Reference Resolution</strong>, the ideal resolution for the assets on screen. We don’t necessarily need to do this though.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*0EVD6DKl2M_iSVOFtXg73A.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*T6kt2f8VjGfQWD22du8nLg.gif" /></figure><p>Most of the <strong>Assets </strong>that we will be using will be <strong>Images</strong>. To add one to our <strong>Canvas</strong>, we simply right-click on the <strong>Canvas </strong>and select <strong>Create -&gt; UI -&gt; Image</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*8mi6EMGn1niOu7aq-_8Yrw.gif" /></figure><p>This will add an <strong>Image </strong>to the center of the <strong>Canvas Object</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*403eg2QgARjonu72rzw3aA.png" /></figure><p>Likewise, it will make the <strong>Image </strong>a <strong>Child </strong>of the <strong>Canvas</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/173/1*2gn4u-12D4wHfr4tJxYyHg.png" /></figure><p>Right now, the <strong>Image </strong>appears as a plain white square. We will need to assign a <strong>Sprite </strong>to the <strong>Image </strong>in order to get an actual <strong>Image </strong>to display. Let’s start with our background. We select the <strong>Image </strong>in the <strong>Hierarchy </strong>and drag a <strong>Sprite </strong>into the <strong>Source Image </strong>slot of the <strong>Image</strong> <strong>Component</strong>. This will swap out that blank square with our <strong>Sprite</strong>. Any transparency the Sprite has will also show up in the Image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*tevg28Cw7JNj83y4LCI7lA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/344/1*zst6XJqFMIfckdNcAd1L9w.png" /></figure><p>We can now adjust the size of the <strong>Image </strong>to fit our needs by using the <strong>Rect</strong> <strong>Tool</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*DUYSXwaJbc2p08C9Y4mIpA.gif" /></figure><p>We should also rename our <strong>Image </strong>to reflect what purpose the Image has.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/271/1*GJOZCQmYPL1xdnxtswO_xw.gif" /></figure><p>Now, we can add a few more <strong>Images </strong>to fill out the empty space a bit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*Qse8w4UwfoIq2CKFnlGYdw.png" /></figure><p>Now, we can add some <strong>Text </strong>to the <strong>Titlebar </strong>using the <strong>TextMeshPro Component</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*CQQtgZSvQZJgzfKNn_WI5w.gif" /></figure><p>The text is a bit too small, especially for a <strong>Titlebar</strong>. Additionally, the <strong>Component </strong>itself is entirely too small as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*oeNhBmRXT15v6voFIQGPrQ.png" /></figure><p>We can fix this by extending the <strong>Textbox </strong>to fill the <strong>Background Image</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*XvvmLSUafsvEwzC3wKmULw.gif" /></figure><p>Now, we can adjust to <strong>Text </strong>to be more appropriate for the scenario.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*wnZwsJzFjzgU9bhybWoLeA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/276/1*DtrUjjHgzMVWgpg9jKB4aA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/1*THms_ovFhPTLU8r8ZUr9xA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/272/1*6FOiHuVuUX9y83Oc6E3QRQ.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/244/1*xozYUpvbDNN6V3xIv7yi2w.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/278/1*yUVEcT6ZdFSuyl4GkYTACA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*as5Mtyp3d5Pef6tMzAF4lQ.png" /></figure><p>That’s a bit better! Now, we need to add some <strong>Buttons</strong>, which can be easily done through the <strong>Create Menu</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*aC3n9X9xCLMxWlJySJGawQ.png" /></figure><p>It’s pretty plain and small. Let’s add an <strong>Image </strong>and resize it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*RZqFispbkEH1vlLjFM_Frg.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*V2WHSdqRo_7FzMVtl9wydA.gif" /></figure><p>As you can see, it comes with its own <strong>Text Component</strong>. We can adjust this the same way we adjusted the <strong>Text </strong>for the <strong>Titlebar</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/279/1*zImbOeKWVyYnPyTV_YuCPQ.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/267/1*v3Z094tzBiFbwg4CFzWBvQ.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*ShGZ-jLADxDIa-tX9GdUAA.png" /></figure><p>Like everything else, we need to name this appropriately.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/233/1*YHzo7JV8iJYNBI-qd7pHUg.gif" /></figure><p>We can also forgo the <strong>Text </strong>for a <strong>Button </strong>and use an Image instead. For instance, we have another <strong>Button</strong>, an exact duplicate of our <strong>StartButton</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*9Ug7nyymoMt7rp_qmM2lVw.png" /></figure><p>We can delete the <strong>Text</strong>…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/214/1*U7-VKKdJ5g-6jovr6KXYDQ.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*1BE4iVpLdl_pgvp4qZkKmg.gif" /></figure><p>Add an <strong>Image </strong>to it…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/278/1*DyTf7Z1eZXR3v_gPrKqpWQ.png" /></figure><p>We can make it fit by selecting an <strong>Anchor Point </strong>and pressing the <strong>Alt </strong>key…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/277/1*CqnbZ4rGrGfNQFUd_WyJlQ.gif" /></figure><p>And then assigning a <strong>Sprite </strong>to the <strong>Image</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*le4i5W6GFuFeiT_U0rkt7Q.gif" /></figure><p>This may look a bit wonky at first but don’t worry. We can fix it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/293/1*mfdMQUjSk-5aSNA50UTybw.png" /></figure><p>We just need to click the <strong>Preserve Aspect</strong>. This will keep the <strong>Image Proportions </strong>the same as the original <strong>Sprite </strong>as we <strong>Scale </strong>up and down.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*ncGHCF2Vygtes9PKneEUWg.gif" /></figure><p>Since we have this attached to a <strong>Button</strong>, we should also uncheck the <strong>Raycast Target</strong> while we are here as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/277/1*u6nS9CL-Izi5K0KV7msLHA.gif" /></figure><p>Now, when we resize the <strong>Button</strong>, the Image will adjust its size as well without being deformed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*Qa1VBz2S_I4_sGp0P7oF3w.gif" /></figure><p>Now, that looks pretty good.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/1*joBmHbcg_stQGDs9TTnNXA.png" /></figure><p>Now, we have all the techniques to make a decent-looking Menu. We just need to rinse and repeat and maybe get a bit creative. Don’t be afraid to go all out with it either.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*u0eTjjCAdlB6xgpPmB-Omg.png" /></figure><p>Thanks!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=624daf26bb59" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a UI Minimap in Unity]]></title>
            <link>https://medium.com/@dcargile84/build-a-ui-minimap-in-unity-92dfc21f8519?source=rss-dd67903bab0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/92dfc21f8519</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[made-with-unity]]></category>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[game-design]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Dustin Cargile]]></dc:creator>
            <pubDate>Wed, 03 Apr 2024 05:43:29 GMT</pubDate>
            <atom:updated>2024-04-03T05:43:29.345Z</atom:updated>
            <content:encoded><![CDATA[<p>A minimap is a unique <strong>UI Element</strong> that can convey multiple things to a <strong>Player</strong>. We can show the location of resources, enemies, hazards, etc. There are also a multitude of methods to creating a minimap. Some methods are extremely complex and use cameras and raw images. For our example, we will just use a simple <strong>Sprite </strong>to act as our map.</p><p>We start off with just a <strong>Plane </strong>a couple of <strong>Capsules </strong>to act as the <strong>Player </strong>and an <strong>Enemy</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/172/1*ZJKtjCntbzUXG1p8eJIvpg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*PWAzBWVnWDAYToINaE9HUA.png" /></figure><p>Now, we will add our <strong>Map </strong>object. This consists of a <strong>Canvas </strong>with 3 images on it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/259/1*ggDYP2HLgW8dUjY1BFX8Ww.png" /></figure><p>Now, we have our <strong>Plane </strong>set to certain size values to make it a square.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/1*OOW6aQWIhA-hq8sYNwoCmg.png" /></figure><p>We also set our <strong>Ground Image </strong>to reflect those values but multiply by 10 to give the image some scale.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/284/1*_8XO2-pRb99JZEQTfIqZrg.gif" /></figure><p>Resulting in this image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/310/1*bjqDUuAbZXhmAYXPknvfxQ.png" /></figure><p>Now, we add another <strong>Image </strong>to act as a <strong>Mask</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/204/1*kDQ_OkLn3n5a46SnaX7y3g.gif" /></figure><p>We now add the <strong>Mask Component </strong>and adjust the <strong>Hierarchy </strong>so that the <strong>Ground Image </strong>is a child of the <strong>Mask</strong>. We will also make the <strong>Player Image </strong>a child of the <strong>Mask </strong>and the <strong>Enemy </strong>a child of the <strong>Ground</strong>. (The idea here is that the <strong>Player Image</strong> will not move but rather the <strong>Ground Image</strong> will and move the <strong>Enemy Image</strong> with it.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/1*FaG2sqYQkeu-acK1ukx-gA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/199/1*3X8nNrnZpBrFz2K-fIArJg.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/189/1*1NrDmCkKKvi_M3h7oC4Iag.gif" /></figure><p>We should now have this image on the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/319/1*GX66Zp0RunzmwhHZ49IlCA.png" /></figure><p>Now, we can drag the entire map to our desired location.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*KjO8yMfHupkBUAZ6gXqBNw.gif" /></figure><p>We will create an <strong>Empty GameObject </strong>to hold our <strong>Map </strong>in, which we will anchor to the top right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/262/1*sTkpoyjlOgOznbq9lTEztw.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/323/1*c1yA2P6F8t197vuWTM-13A.gif" /></figure><p>This will keep the <strong>Map </strong>anchored when we change <strong>Aspect Ratios </strong>and of course, will clean up our <strong>Hierarchy</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qaYdwIHKbAhE_368RtJBOw.gif" /></figure><p>We create a new <strong>Script </strong>called <em>Minimap </em>and now we need to code the minimap. This is extremely easy as we only need 4 things. We need references to: the <strong>Player</strong>, the <strong>Enemy</strong>, the <strong>Map Background Image</strong>, and the <strong>Enemy</strong> <strong>Image</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/413/1*u1rsT7ZHyM4Zy1lZSf1iTQ.png" /></figure><p>We create a new <strong>Manager </strong>object…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*vfrw6IHSq367m5X9Sy1Xjw.png" /></figure><p>Give it the <strong>Minimap Script</strong>…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*1smfab0lrV1oGTgmYuWboQ.gif" /></figure><p>And assign the appropriate objects in the <strong>Inspector</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*Cpy71YZpWLb22e_hdeJ8vQ.gif" /></figure><p>Now, we can add some logic. We will use the inverse of the <strong>Player’s X and Z</strong> coordinates to determine where the <strong>RectTransform </strong>of the <strong>Map Image </strong>is. In other words, the <strong>Map Image </strong>will move in the opposite direction that the <strong>Player </strong>moves giving the illusion that the <strong>Player </strong>is moving across the <strong>Map</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*N-xWtDKFa9wUKyRlysWs7w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*mCUJR6O6g6tVD-bdE8GjGw.gif" /></figure><p>Now, we can also add the <strong>Enemy </strong>movement on the map a well. We will copy the same logic that we used on the <strong>Player </strong>but will be affecting the <strong>Enemy</strong> <strong>Image</strong>. This also means that we do not have to invert the values of the <strong>Enemy Position</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*5-H2H7QG-SFZKoyfUSXIPQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*EOJXWL_k4Ng7OCZZLTOksg.gif" /></figure><p>And that’s it!! We have a simple working <strong>Minimap</strong>.</p><p>Thanks!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92dfc21f8519" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to mask UI Elements in Unity]]></title>
            <link>https://medium.com/@dcargile84/how-to-mask-ui-elements-in-unity-1d2abd2d1bfa?source=rss-dd67903bab0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d2abd2d1bfa</guid>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[made-with-unity]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Dustin Cargile]]></dc:creator>
            <pubDate>Mon, 04 Mar 2024 19:54:21 GMT</pubDate>
            <atom:updated>2024-03-04T19:54:21.091Z</atom:updated>
            <content:encoded><![CDATA[<p>Masking <strong>UI Elements</strong> is an incredibly useful tool available to us in <strong>Unity</strong>. It is also incredibly easy to implement. All we need is two Images and a little bit of work.</p><p>We start with two Images, three if we count the <strong>Background</strong>. Both of these Images are Sprites with unique shapes. In this case, the <strong>X </strong>is the <strong>Mask </strong>and the wooden pallet is the <strong>Image </strong>that will be masked out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/159/1*E-lQqSmRg4XFzAJOzYSjiw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*12wyCJrrODMdddibqxREMA.png" /></figure><p>We need to make the <strong>Image </strong>a <strong>Child </strong>of the <strong>Mask</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/185/1*fwe0_TIMtXUtyhCGgaLqjw.gif" /></figure><p>On the <strong>Mask </strong>object, we add the <strong>Mask Component</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/292/1*Oa6ckYujJNGcQrCFovbUWQ.gif" /></figure><p>Now, as we move the <strong>Image </strong>across the <strong>Mask</strong>, the <strong>Image </strong>will only show up where the <strong>Mask </strong>would be visible. Another way to look at this is that the <strong>Image’s Alpha Channel</strong> will only be visible where the <strong>Mask’s Alpha Channel</strong> is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*ZWvLmFbA_YLZFyWnfTpvWA.gif" /></figure><p>There is another masking method that we can utilize. <strong>The Rect Mask 2D</strong> will also work if the shape that we want is rectangular. If we use just a standard <strong>Image </strong>without a <strong>Sprite </strong>attached, we can add the <strong>Rect Mask 2D</strong> <strong>Component</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*OTHYAJZvMpWlLCMzB6pZUw.gif" /></figure><p>We can then adjust the <strong>Padding </strong>options to alter the <strong>Mask</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/268/1*Dw5Xb6JEaJKrBLZhowmZlg.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*o_mvSkhZP3F18IgWgOP6qg.gif" /></figure><p>We can also add some <strong>Softness </strong>to blur out the edges.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/278/1*A3EFtUEK5kjDwyOlMsJ9DQ.gif" /></figure><p>Now, we can move our <strong>Image </strong>around to see how our <strong>Mask </strong>is working.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*SPrnCaOdp_16d6OwZUIvlQ.gif" /></figure><p>Lastly, we can turn off the <strong>Image Component </strong>of our <strong>Mask </strong>so that we only see the <strong>Masked Image</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/1*tCk0i-4gb7crqwaBSzPAWA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/281/1*MWqoMKFHaE7G1UPgUg6g5Q.gif" /></figure><p>Now that we have gone over all of that, a practical use for this is this <strong>Scrollbar</strong>. These <strong>Scrollbars </strong>each have a series of <strong>Images </strong>and <strong>Text </strong>that scroll up and down. Combined with gradient overlays and a <strong>Mask</strong>, we can achieve the illusion that the numbers are rolling instead of just up and down.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/291/1*bpIyDVn6D4__-CHRsbgQfg.gif" /></figure><p>In all actuality the Mask makes the <strong>Images </strong>disappear when they are not within the viewable area.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*Q0QZL4GyDPFRMf_M2-EfSA.gif" /></figure><p>Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d2abd2d1bfa" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>