<?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 GameDev Dustin on Medium]]></title>
        <description><![CDATA[Stories by GameDev Dustin on Medium]]></description>
        <link>https://medium.com/@gamedevdustin?source=rss-e6424952cb6a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*rc6pfqz60PZyYqdcN3000Q.jpeg</url>
            <title>Stories by GameDev Dustin on Medium</title>
            <link>https://medium.com/@gamedevdustin?source=rss-e6424952cb6a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 13:03:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gamedevdustin/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[The “Parent Trap” Coroutine]]></title>
            <link>https://blog.devgenius.io/the-parent-trap-coroutine-3f1e4d31d9e9?source=rss-e6424952cb6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f1e4d31d9e9</guid>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[gamedev]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[unity-development]]></category>
            <dc:creator><![CDATA[GameDev Dustin]]></dc:creator>
            <pubDate>Mon, 08 Jul 2024 23:05:40 GMT</pubDate>
            <atom:updated>2024-07-17T17:34:29.357Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nu8gQwT6djhxctT0AwtzJg.gif" /></figure><p>If you’ve ever run into a timing issue where you have a hierarchy of nested gameobjects attempting to populate data using one another, then this article might be for you.</p><p>Note, this approach works in one direction, top-to-bottom, though it could be modified to operate in reverse.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*go-A6F3l4CfLp1gRmGbFJw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OAJOeQvnMoABdkJirGZBLQ.jpeg" /></figure><p>In my use case, I have a hierarchy with many gameobjects who all have the Part class / component on them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ASOXh7IPOd6wrjopKs3P6w.jpeg" /></figure><p>This class inherits from IPart.</p><p>Essentially, I want to be able to reference in code the attributes I’ve listed in the naming structure of my gameobjects.</p><p>From other classes, I’d like to be able to grab a gameobject’s Part components and know some useful information about that gameobject, something along the lines of “Frame” &gt; “Stop” &gt; “Side 1”.</p><p>Or in simpler terms, this gameobject is the Side 1 game object of the frame stop.</p><p>But each gameobject’s Part component tries to assign based off of it’s parent gameobject’s Part component and so forth.</p><p>All of which are running during Unity’s OnEnable().</p><p>How do I force them to do this sequentially?</p><p>Short answer: How many parents deep is it?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nhe5gnsdFR0JDrKEVd0cvg.jpeg" /></figure><p>The relevant bit here is the StartDelayCoroutine which A) uses GetNumberOfParents() method to pass in the parent depth of this gameobject (i.e. 1 parent? 2? 5?) and an associated method as an Action (CopyParentPartValues) that will execute at the appropriate time.</p><p>Note that this approach will only pass a method without parameters as an Action.</p><p>It would take more work to handle a method with parameters.</p><p>Fundamentally, so long as the root parent has accurate Part component information assigned on it before the child gameobject grabs that information, everything should be okay.</p><p>But how do we do set up a coroutine to make that happen?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nu3lNMS5pJS7bK_q3ykhGA.jpeg" /></figure><p>First, we use a utility method to recursively get the total number of parents/grandparents this gameobject has with GetNumberOfParents().</p><p>With that information we can setup StartDelayCoroutine() and IEnumerator DelayExecution().</p><p>Notice that DelayExecution() takes in an int parameter for numOfParents and an Action.</p><p>Now, we can just set the delay time as numOfParents multiplied by 0.1!</p><p>So, 1 parent = 0.1f, 3 parents = 0.3f, and 5 parents = 0.5f and so forth.</p><p>This forces a root-to-trunk-to-branch-to-twig-to-leaf-to-fruit type of execution.</p><p>So long as child objects get their information exclusively from parent objects, and NOT vice versa, we can be assured that the Part object information of the parent which is pulled from has updated prior to being called and used to update the child gameobject’s Part component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3aAPuQ1-imOJmYOnSMnbLg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*or0iJOu8Vb6QSSmzFCsJCQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ayoimnsAEw6im-po2JhgGw.jpeg" /></figure><p>Just for the sake of full context, I’ve included the remaining methods of the Part class from my use-case.</p><p>Essentially, the enum type variables are being pulled from parent Part components (at the proper time!) and the name of the gameobjects are being compared to accurately define the Part component of the current gameobject.</p><p>I slapped this article together pretty quickly, so please forgive the mess.</p><p>I hope somebody finds it helpful despite that!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f1e4d31d9e9" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/the-parent-trap-coroutine-3f1e4d31d9e9">The “Parent Trap” Coroutine</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Detecting Sequential Keypresses with the New Input System in Unity 2023]]></title>
            <link>https://gamedevdustin.medium.com/detecting-sequential-keypresses-with-the-new-input-system-in-unity-2023-302a2322ff0a?source=rss-e6424952cb6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/302a2322ff0a</guid>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[unity-development]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[unity-input-system]]></category>
            <dc:creator><![CDATA[GameDev Dustin]]></dc:creator>
            <pubDate>Fri, 08 Sep 2023 16:11:05 GMT</pubDate>
            <atom:updated>2023-09-08T16:11:05.064Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*sh6Bxu7HcWhu9aJ8VgYU-w.jpeg" /></figure><p>In this article we’ll look at how we can use Unity’s new Input System package to check for sequential keypresses.</p><p>We’ll set it up so that pressing the Tab key will start an algorithm that gives the user 8 seconds to type in a code.</p><p>And we’ll do this without any text input boxes what so ever!<br> <br>Think back to the early days when you could push button combos to unlock cheats and you’ll get an idea of what we are doing here.</p><p>But this doesn’t have to be used just for cheat functionality.<br>This can be used with minor modification any time you want to detect a certain string of input.<br> <br>This could be the foundation for a new bad-word filter if you wanted to do that.</p><p>Now, the Input Asset itself does not have this functionality, but we can still use the new “Keyboard.current” functionality provided by the new Input System to get what we need.</p><p>Specifically, we’ll be using “Keyboard.current.onTextInput” which replaced the legacy input system’s “Input.inputString” functionality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*WZyLqiI7nGoApDigiFnT1A.jpeg" /></figure><p><a href="https://docs.unity3d.com/Packages/com.unity.inputsystem@1.6/manual/Keyboard.html?q=OnTextInput">Keyboard support</a></p><p><strong>Keyboard.onTextInput<br></strong>Per Unity’s documentation, it is best practice to use Keyboard.onTextInput for text input in general.</p><p>Basically, any time a user would be typing into a text box or something similar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*lmnpkbHLxPQIfSv6yir9LA.jpeg" /></figure><p><strong>Basic Setup<br></strong>We won’t go over the nitty gritty of getting an Input Asset setup in this article.</p><ul><li><a href="https://gamedevdustin.medium.com/setting-up-the-new-unity-input-system-c95eec72abc7">Setting Up the New Unity Input System</a></li><li><a href="https://towardsdev.com/creating-the-input-asset-for-the-new-input-system-in-unity-2021-8abae6a4c652">Creating the Input Asset for the new Input System in Unity 2021</a></li></ul><p>If you need a refresher, see the articles above.<br> <br>For more articles on the new Input System, go to my Medium page and scroll down to around June/July of 2022.</p><p><strong>TLDR<br></strong>So basically, we have an Input Asset, with an Input Action Map called “Instructor” that has an Input Action called “StartKeySequence” which has been assigned the Tab key as a binding.</p><p><strong>Two Classes Working Together<br></strong>I have two classes that implement this functionality.<br> <br> The first handles the game input from the input asset in general.<br> I’ve cropped it down to just the relevant bits.</p><p>Let’s call it the InputHandler class.</p><p>The other class has a long-winded name for reasons I won’t get into.<br> <br> You should probably just call it CheckKeypressSequence or something along those lines.</p><p>Now, I’ve got these classes attached to the same gameobject as components.</p><p>The InputHandler class has a reference variable for the CheckKeypressSequence class called “_checkForInputSequenceKeyboard”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*UmvzR_5jusrdQyAsPl8Emg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*bzPXmhZhHdldk6s4inMQAw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*bBHctcEOFOGlvov7g-r_Hg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/326/1*4ilKZUKrJLB414mLVzXcqQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*rLQSl-VVm2W-CIiQenwNAg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*7Jul6sgfowFfPI-cc3uHxA.jpeg" /></figure><p><strong>The InputHandler Class<br></strong>I’ve left out the using and class variables section, but you know the drill.</p><p>Add a using statement to the UnityEnginer.InputSystem and you can infer any class variables (denoted starting with a “_”) as needed.</p><p>So, what’s going on here?<br> <br>To put it briefly, we’ve instantiated or Input Asset as a class variable and enabled the Instructor Action Map.</p><p>We then add subscribers/unsubscribers in OnEnable() and OnDisable() which is a good convention to follow any time you use subscribers.</p><p>There we subscribe to the Instructor (Action Map) StartKeySequence (Action), specifically the “performed” event.</p><p>The OnInstructorStartKeySequencePerformed() method then calls the referenced CheckKeypressSequence class which is stored as a class variable (_checkForInputSequenceKeyboard).</p><p>It calls one simply public method from the CheckKeypressSequence class, the “StartCheckingSequence” method.</p><p>Essentially when the new Input System’s Input Asset triggers the StartKeySequence Action’s performed event, we need only to tell the CheckKeypressSequence to do its thing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/317/1*xfqDCQEqZ-mYiNKr_0hzRg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*yBWg9dNRhzXdrnpuqsmavg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*JUYdy5bKHA_WovFPUyp1_A.jpeg" /></figure><p><strong>The CheckKeypressSequence Class<br></strong>This class has plenty of room for improvement!<br> <br>That includes List&lt;&gt; functionality and JSON storage of expected sequences.<br> <br>But in this article, we just have a simple implementation based on one string at the class variable level called “_strSequence”.</p><p>We have some simple class variables that track how long should the user be allowed to input the sequence, how long has the user been inputting the current sequence, and of course what is the current sequence input thus far.</p><p>I’ve renamed (not shown) _isTriggeringInput to _isTriggeringKeybind for clarification.</p><p>Basically, the Keyboard.current.onTextInput catches the initial keybind if it is also a keypress.</p><p>We don’t want the initial “Tab” keypress that was assigned in the Input Asset to count as part of our sequence (or cheat code).</p><p>The only public variable, “IsCheckingSequence”, is necessary to keep the triggering keybind in the InputAsset from resetting the _strCurrentSequence if it happens to also be part of the valid sequence.</p><p><strong>The Start() Method<br></strong>In Start(), we’ve call a method to hard code the sequence it is looking for.</p><p>In a production situation, you’d probably want to do something with JSON here and implement Lists&lt;&gt;.</p><p>We also subscribe to the Keyboard.current.onTextInput event.</p><p>Probably best to actually put that subscription in OnEnable().</p><p>Again, we unsubscribe in OnDisable() just as we did in our InputHandler class.</p><p><strong>The OnTextInput() Method<br></strong>This method is subscribed to the Keyboard.current.onTextInput event.</p><p>Any time the user is typing, this event is triggered.</p><p>The event passes us the current character that was pressed.<br> <br>If this happens to be the keybind, we ignore it and return out of the method.</p><p>Otherwise, if IsCheckingSequence is true, we know that we are actively listening for an input sequence.</p><p>In that case, we add the new character to the previous characters by updating the _strCurrSequence class variable.</p><p>We then call the CheckSequences() method which will compare the _strCurrSequence to any predetermined sequence we have in mind.</p><p><strong>The SetKeySequence() Method<br></strong>This is just a quick dirty method for hard coding a sequence to check against.<br> <br>Put “cheatalpha” as an assignment to _strSequence.</p><p><strong>The CheckForPlayerSequences() Method<br></strong>And last, here we check the current sequence that has been entered against the expected sequence.</p><p>In a production or simply to be more robust, we’d have some list comparison functionality here.<br> <br>But for this demonstration, this will do the trick.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=302a2322ff0a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unit Testing Classes from Other Assemblies with Unity’s Test Framework in Unity 2022]]></title>
            <link>https://gamedevdustin.medium.com/unit-testing-classes-from-other-assemblies-with-unitys-test-framework-in-unity-2022-820b3e3486fb?source=rss-e6424952cb6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/820b3e3486fb</guid>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[unit-test-framework]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[unit-testing]]></category>
            <dc:creator><![CDATA[GameDev Dustin]]></dc:creator>
            <pubDate>Thu, 31 Aug 2023 15:16:11 GMT</pubDate>
            <atom:updated>2023-08-31T15:16:11.509Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PjzgGSLUMqAAozq8A3iaGg.gif" /></figure><p>In this article we’ll move onto some more real-world applications for Unity’s Test Framework package.</p><p>It’s nice to test bits of code within the Testing folder, but we’ll spend most of our time testing projects with complex existing code bases.</p><p>If you’re just diving into the Unity Test Framework for the first time, I recommend reading the QuickStart Guide first:</p><p><a href="https://gamedevdustin.medium.com/quickstart-guide-unitys-test-framework-in-unity-2022-1ee25fe94765">QuickStart Guide: Unity’s Test Framework in Unity 2022</a></p><p>You may also want to check out “Creating a Play Mode Test with Unity’s Test Framework” here:</p><p><a href="https://gamedevdustin.medium.com/creating-a-play-mode-test-with-unitys-test-framework-in-unity-2022-a0b8d67aa31d">Creating a Play Mode Test with Unity’s Test Framework in Unity 2022</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*U7ijKEQq3rBmrAb6BSErTQ.jpeg" /></figure><p><strong>The PlayTest_NPC_Controller Class Project Location<br></strong>We’ll be running the PlayTest_NPC_Controller class’ unit test methods.</p><p>Note its location in the project hierarchy above.<br> <br>It is in the UTF-PlayTests folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/302/1*WDFyVM8PyHKLntBTh62cXA.jpeg" /></figure><p><strong>The NPCController Class Project Location<br></strong>We can see that the NPCController class we will be unit testing is not in our normal unit testing folders.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*gnysM4X4hrDsQuIEOfklzQ.jpeg" /></figure><p>For us to access the NPCController class from our unit test class, we have to take into account that the NPCController class is from a folder location outside of the UTF-PlayTests folder.<br> <br>We’ll need to add an Assembly Definition Reference for our unit testing class to “see” the NPCController class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*k9IMLpqkhuI5Cjet7uCBrg.jpeg" /></figure><p>Our PlayTest_NPC_Controller class that contains our unit tests will be accessing the NPCController class which belongs to the Game Assembly Definition (asmdef) file.</p><p>As such, we have to add an Assembly Definition Reference to the asmdef that PlayTest_NPC_Controller belongs to.</p><p>The PlayTest_NPC_Controller belongs to the UTF-PlayTests asmdef in the UTF-PlayTests folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*63D8ptBxRqtydsuMGwwjzA.jpeg" /></figure><p><strong>The NPCController Class<br></strong>Now that we have set our unit testing asmdef file to “see” the gameplay asmdef, let’s take a look at the class we’ll be unit testing.</p><p>There are just a few basic methods in here.</p><p>We can setup a unit test for each of them, but I’ll just being unit testing the MoveNPCTowards() and TeleportNPC() methods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rQVKW42k54IKuPmGq__chA.gif" /></figure><p><strong>Create the PlayTest_NPC_Controller Class<br></strong>If you haven’t already, right click in the UTF-PlayTests folder and go to Create &gt; Testing &gt; C# Test Script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*3yKd36q4xRHtT8FRp8-ZsA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*UwpIP8yJqMUg1GgIYLE2zQ.jpeg" /></figure><p>Above we can see the general Arrange, Act, Assert pattern in use for two separate Unit Tests that will run in Play mode.</p><p>First, each method loads the scene that needs to be tested.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*YAQv5jBHASFJ7ovwaEPDzg.jpeg" /></figure><p>In this scene, I have an “NPC_Manager” gameobject with the NPCController class attached as a component.</p><p>I’ve assigned a simple sphere gameobject prefab called “NPC_Default”.</p><p>Each unit test method will get this gameobject by searching for the tag “NPC_Manager” and then grab the NPCController class attached.<br> <br>From there, we can run any public method on the NPCController class.</p><p>Using the NPCController class, we’ll simply instantiate the NPC_Default prefab, move it, and then verify that it moved.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PjzgGSLUMqAAozq8A3iaGg.gif" /></figure><p><strong>Run the Unit Tests<br></strong>And as we can see above, both unit tests run and complete successfully.<br> <br>Excellent!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=820b3e3486fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Play Mode Test with Unity’s Test Framework in Unity 2022]]></title>
            <link>https://gamedevdustin.medium.com/creating-a-play-mode-test-with-unitys-test-framework-in-unity-2022-a0b8d67aa31d?source=rss-e6424952cb6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0b8d67aa31d</guid>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[unit-test-framework]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[unittest]]></category>
            <dc:creator><![CDATA[GameDev Dustin]]></dc:creator>
            <pubDate>Wed, 30 Aug 2023 17:56:38 GMT</pubDate>
            <atom:updated>2023-08-30T17:56:38.566Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bJXluNOnuP02FSHLUa9P-A.gif" /></figure><p>In this article, we’ll use Unity’s Test Framework to run Play Mode tests.</p><p>Play Mode tests will be used for testing our gameplay related code.</p><p>Per Unity’s documentation:</p><p>“You can run Play Mode tests as a standalone in a Player or inside the Editor.</p><p>Play Mode tests allow you to exercise your game code, as the tests run as coroutines if marked with the UnityTest attribute.”</p><p>If you’re just diving into the Unity Test Framework for the first time, I recommend reading the QuickStart Guide first:</p><p><a href="https://gamedevdustin.medium.com/quickstart-guide-unitys-test-framework-in-unity-2022-1ee25fe94765">QuickStart Guide: Unity’s Test Framework in Unity 2022</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*xRvImABxukPLlW_dA7sKVg.gif" /></figure><p>To get started, switch from “EditMode” to “PlayMode” in the Test Runner window.</p><p>Click the “Create PlayMode Test Assembly Folder” button and then the “Create Test Script in current folder” button.</p><p>Name it something appropriate to your use-case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*WnWcot2AIKvuQd-gx71wqQ.gif" /></figure><p><strong>Referencing the Game Assembly (asmdef) File<br></strong>Let’s go ahead and add the “Game” asmdef (Assembly Definition file) we created in the QuickStart Guide article to the newly created UTF-PlayTests asmdef file.<br> <br>We did this for the UTF-EditorTests asmdef file in the previous article as well.</p><p>This is a prerequisite for unit testing of classes that are not part of the Editor or Play mode asmdef folder structures.</p><p>With this reference we’ll be able to test gameplay classes associated with the Game asmdef file.</p><p>We’ll cover that use-case in the next article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*2qINVfaUzzVEjDP8mELltg.jpeg" /></figure><p>Make sure to click the Apply button in the Inspector window after adding the asmdef file reference.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*C7jMlcFLf2anEt1vCZTwhw.jpeg" /></figure><p><strong>The PlayTest01 Class<br></strong>The PlayTest01 class we generated is practically identical to the UTF-EditorTest01 class we created in the previous article.</p><p>That’s because the only difference is which Assembly File (Editor or Play mode) the class belongs to and naming of course.</p><p>The Test Framework than does all of the work in the background based on the asmdef file to run the test at the correct time based on target platform and referenced asmdef files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*nfsFNDXj1LNgTuvHTKTMbA.jpeg" /></figure><p><strong>Warning: Bloated Build Size Ahead!<br></strong>Per Unity’s documentation, we need to be wary of project bloat when using Play Mode unit testing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*jEGMo4fc7qkI0evo0RM_rQ.gif" /></figure><p>However, in Unity 2022.3.8f1, I did not see the “Disable PlayMode tests for all assemblies” option shown above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*M1nEFUFX87sl1XeB3w54Dg.jpeg" /></figure><p>Since Unity automatically adds a Define Constraint of “UNITY_INCLUDE_TESTS” on the asmdef files for unit testing, they are probably already excluded from project builds.</p><p><a href="https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html#conditional-assembly">Assembly definitions</a></p><p>According to Unity’s documentation:<br>“You can use preprocessor symbols to control whether an assembly is compiled and included in builds of your game or application (including play mode in the Editor).</p><p>You can specify which symbols must be defined for an assembly to be used with the Define Constraints list in the Assembly Definition options.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vi96y7PU4_frO648aFV9XA.jpeg" /></figure><p><a href="https://docs.unity3d.com/Manual/CustomScriptingSymbols.html">Custom scripting symbols</a></p><p>According to Unity’s documentation:</p><p>“C# directives allow you to selectively include or exclude code from compilation, based on whether certain scripting symbols are defined or not defined.”</p><p>If we navigate to Project Settings &gt; Player &gt; Other Settings &gt; Script Compilation, we can see that there are no Scripting Define Symbols listed.<br> <br>For the unit testing scripts to be compiled in a build, we’d probably need to add “UNITY_INCLUDE_TESTS” to the list.</p><p>To explicitly exclude unit testing scripts, we might add “!UNITY_INCLUDE_TESTS” to the Script Compilation &gt; Scripting Define Symbols.</p><p>Please leave a comment if you have more insight into this topic!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*jJFBV2jmin71RJG-Cl7Bwg.jpeg" /></figure><p><strong>Back to the Unit Test Code</strong><br>Using the same unit test code from our EditMode unit testing, we’ll update the PlayTest01SimplePasses() method and see what happens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*2_2E7bAmQo-ZdoAqsA06Fg.gif" /></figure><p>Since the assertion is that the sum will equal 15, but the vars are 5 and 3 (5 + 3), we can see that the test fails as expected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*7qeITm_c0mlD2dykAAK_0Q.jpeg" /></figure><p>Let’s rewrite the test code with the expectation that the unit test will pass by setting the y value to 10 (5 + 10 = 15).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*OiqrdXFRi-2OM7mum6JSFg.gif" /></figure><p>Running the unit test now shows as successful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*_nLeFfRS9e-7Y5tqfN3-IA.jpeg" /></figure><p><strong>Finally, an Actual Play Mode Unit Test<br></strong>Let’s add some simple logic to create a gameobject and then move it.</p><p>We’ll then assert that the gameobject’s position is no longer where it was originally instantiated.</p><p>Remember to end with “yield return null” or the test won’t stop running play mode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bJXluNOnuP02FSHLUa9P-A.gif" /></figure><p>When we run the unit test, we can see the gameobject being created, moving, and then the test showing as successful.</p><p>Perfect!</p><p>In the next article we’ll cover running unit tests on code that exists elsewhere in our project!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0b8d67aa31d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[QuickStart Guide: Unity’s Test Framework in Unity 2022]]></title>
            <link>https://gamedevdustin.medium.com/quickstart-guide-unitys-test-framework-in-unity-2022-1ee25fe94765?source=rss-e6424952cb6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ee25fe94765</guid>
            <category><![CDATA[unittest]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[unit-test-framework]]></category>
            <dc:creator><![CDATA[GameDev Dustin]]></dc:creator>
            <pubDate>Tue, 29 Aug 2023 19:26:01 GMT</pubDate>
            <atom:updated>2023-08-29T19:26:01.092Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/335/1*ETtuqmaNBoRqyUf1YSdxQQ.gif" /></figure><p>In this article, we’ll cover Unity’s built-in Test Framework package for unit testing.</p><p>This package allows developers to either do Test-Driven development or Unit Testing in general.<br> <br>I’ll be doing the latter for this article in order to showcase the functionality Unity has put at our fingertips.</p><p>As always, the definitive information on this subject is Unity’s own documentation, which can be accessed here:</p><p><a href="https://docs.unity3d.com/Packages/com.unity.test-framework@1.1/manual/index.html">About Unity Test Framework</a></p><p>Per Unity’s documentation:<br>“UTF uses a Unity integration of NUnit library, which is an open-source unit testing library for .Net languages. <br> <br>UTF currently uses NUnit version 3.5. <br> <br>For more information about NUnit, see the <a href="http://www.nunit.org/">official NUnit website</a> and the <a href="https://docs.nunit.org/">NUnit documentation</a>.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*ctpsISZZ7LvjQIfMj8C7hQ.jpeg" /></figure><p><strong>The Test Framework Package<br></strong>The Unity Test Framework package is most likely installed by default.</p><p>You can check by opening Package Manager &gt; Packages: Unity Registry and scrolling down to “Test Framework”.<br> <br>If it’s not installed, you can do so here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*3ajgicYWp7cTMTp3XVzz0w.gif" /></figure><p><strong>Keeping Our Project in Order<br></strong>In our project, we’ll want to keep our unit testing files separate from our game files.</p><p>Start by creating a new folder in the Project window called “Game” where all of our gameplay related (not UTF related) files will be stored.</p><p><strong>NOTE:</strong> Disregard creating the “UnitTesting” folder that was shown above.<br>Test folders are created automatically using the TestRunner window in Unity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*aQy5rXB0RJdAXzarDcwe5A.png" /></figure><p>Next, open and place the Test Runner window by going to Window &gt; General &gt; Test Runner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*1yp7U6yGZaOYhPYF-v2wCw.jpeg" /></figure><p><a href="https://docs.unity3d.com/Packages/com.unity.test-framework@1.1/manual/workflow-create-test-assembly.html">Workflow: How to create a new test assembly</a></p><p>Per Unity’s documentation:<br>“Unity Test Framework looks for a test inside any assembly that references NUnit.</p><p>We refer to such assemblies as TestAssemblies.</p><p>The Test Runner UI can help you set up TestAssemblies.</p><p>Play Mode and Edit Mode tests need to be in separate assemblies.</p><p>In the Test Runner window, you will see an EditMode tab enabled by default, as well as a Create EditMode Test Assembly Folder button.</p><p>Click the button to create a Tests folder with a respective .asmdef file by default.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*05aLylENKTIRrMrz15hRhw.gif" /></figure><p>Just like the documentation says, we’ll click the “Create EditMode Test Assembly Folder” button and then rename it to suit our taste.<br> <br>I’ve called mine “UTF-EditorTests” for clarity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*nChdj9J6iatLR61sEske2w.gif" /></figure><p>If we navigate within this newly created folder, we can see the asmdef file that was created.</p><p>Under “Assembly Definition References” we can see references to “UnityEngine.TestRunner” and “UnityEditor.TestRunner”.</p><p><strong>Note:</strong> The UnityEditor.TestRunner reference is only available for Edit Mode tests.</p><p>Below those is a reference to the nunit.framework.dll.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*jbuZJO0442usXa9HLXhxLA.gif" /></figure><p><strong>Creating an Assembly Definition (asmdef) File for the Game Folder<br></strong>Because the UTF framework makes use of assembly definition (asmdef) files, we’ll need to create some ourself that it will reference for testing gameplay functionality.</p><p>In this small prototype example project, we’ll create a simple “Game” asmdef file in our Game folder.<br> <br>In a more complex project, you will likely have many more asmdef files which you will need to reference when testing the functionality of a Unity project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9iiAjgPP4sF0djDn0xL6Jg.gif" /></figure><p><strong>Referencing Game Assembly (asmdef) Files from Test Assembly Files<br></strong>For the UTF assembly to “see” gameplay related classes and test their functionality, it will need a reference to the “Game” asmdef file.<br> <br>As shown above, simply display the UTF asmdef file in the Inspector and lock the view for ease of use.</p><p>Then, navigate to the Game asmdef file and drag it into the UTF asmdef file under “Assembly Definition References”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*2qINVfaUzzVEjDP8mELltg.jpeg" /></figure><p>To save this reference, we need to click the “Apply” button at the bottom of the Inspector window for the UTF-EditorTests asmdef file (or whatever you named it).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*vbo3V1tD9xqwtx3sn2ZtpA.gif" /></figure><p><strong>Creating a Test Class/Script<br></strong>To create our first test class, selected the UTF-EditorTests asmdef file and click the “Create Test Script in current folder” button.</p><p>Name it something useful if possible.</p><p>For demonstration purposes, I’ve named it something generic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mOuhG6WdOkdQlxrd7tyoKg.jpeg" /></figure><p>Open the newly created class in your IDE.<br> <br>I’m using JetBrains Rider IDE, so it will look a bit different from Microsoft Visual Studio.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X76EdHWIk8Tnt2SzzH9wdQ.jpeg" /></figure><p><strong>JetBrains Rider AI Assistant<br></strong>As of the writing of this article (August 2023), AI implemented based on Large Language Models (LLMs) has become popular and, finally, useful!</p><p>So much so, that JetBrains and others are integrating AI LLMs into their IDEs.<br> <br>While this can be a two-edged sword, for simple straight-forward questions it can be incredibly useful.<br> <br>I simply highlighted the “[Test]” bit of code, right clicked and asked the AI assistant to “Explain” what I’ve highlighted.</p><p>The response is shown above and gives us a handy demonstration of using the “Assert” class as part of the Test Framework.</p><p>The provided example is a simple method that adds two numbers together that are “asserted” to always equal 15.<br> <br>This is hard coded, but a similar test method in real-world usage would take in two values as parameters before performing this assertion.<br> <br>We’d also want to avoid naming it something vague, as was done in this example.<br> <br>If the answer is always expected to be 15, name it accordingly.</p><p>“public void SumOfNumbersIsFifteen(int num1, int num2)” for example.</p><p>We can see that AI in its current stage is great for giving us a direction for something basic, but we must refine the approach it provides.<br> <br>Never let the AI do ALL of the thinking for you!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ny-sYcc76jMrUlt8i14PlA.gif" /></figure><p>Just to let you see it in action, I’ve asked Rider’s AI Assistant to explain the “[UnitTest]” bit of code.</p><p>This time, no example was given but we still got some useful information out of it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DiqflAjj5A9CZojAPoXl9w.gif" /></figure><p>We’ll use the AI example code to demonstrate running a Unit Test in the Unity Editor.</p><p>Above I’ve copied it over into the default test method with the existing values which should return as valid.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/335/1*ETtuqmaNBoRqyUf1YSdxQQ.gif" /></figure><p><strong>Run the Test(s)<br></strong>In the Test Runner window, select the test(s) you wish to run and click “Run Selected”.</p><p>We can see our “UTFEditorTest01” class which contains the AI generated test code returning with a valid result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*W10XcKCAiC6sCAhz1Gs-rQ.gif" /></figure><p>Back in ourUTFEditorTest01 class, let’s change the “y” value to 3.<br> <br>5 + 3 = 8, not the asserted value of 15, so this test should fail.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*PvXu5597U5EbRv2t2zkgyw.gif" /></figure><p>And indeed, we can see that the test method now fails.</p><p><a href="https://docs.unity3d.com/Packages/com.unity.test-framework@1.1/manual/edit-mode-vs-play-mode-tests.html">Edit Mode vs. Play Mode tests</a></p><p><strong>Edit Mode VS Play Mode<br></strong>Per Unity’s documentation:<br>“Edit Mode tests (also known as Editor tests) are only run in the Unity Editor and have access to the Editor code in addition to the game code.</p><p>With Edit Mode tests it is possible to test any of your Editor extensions using the UnityTest attribute.</p><p>For Edit Mode tests, your test code runs in the EditorApplication.update callback loop.</p><p><strong>Note:</strong> You can also control entering and exiting Play Mode from your Edit Mode test.</p><p>This allows your test to make changes before entering Play Mode.”</p><p>The Edit Mode asmdef file should only target the Editor as a platform.</p><p>“You can run Play Mode tests as a standalone in a Player or inside the Editor.</p><p>Play Mode tests allow you to exercise your game code, as the tests run as coroutines if marked with the UnityTest attribute.”</p><p>In the next article, we’ll cover running unit tests in Play Mode.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ee25fe94765" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The “Any” Key Problem with the New Input System for Simultaneous Input Detection in Unity 2023.1]]></title>
            <link>https://gamedevdustin.medium.com/the-any-key-problem-with-the-new-input-system-for-simultaneous-input-detection-in-unity-2023-1-e436226d4818?source=rss-e6424952cb6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e436226d4818</guid>
            <category><![CDATA[gamedev]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[unity-development]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[GameDev Dustin]]></dc:creator>
            <pubDate>Thu, 15 Jun 2023 21:31:54 GMT</pubDate>
            <atom:updated>2023-06-15T21:33:23.093Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oQILCZK4TsxxKKixhLRGYA.png" /></figure><p><strong>TLDR<br></strong>In the new Input System, the “Any Key” does not pass the name of the key that was pressed, which sucks.</p><p>The “Any Key” also fails to work accurately for detecting simultaneous keypresses when used as the trigger for checking keypress input.</p><p>As shown above when the Y, U, I, and O keys were pressed simultaneously, button states and entire buttons were missed!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/331/1*dRnnnKumtCoOthlSob0q-g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*p9FSixDBM16pi4oMRv3N5A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/1*w7c-W34J5OY4AKtw8Sk_tg.png" /></figure><p><strong>The Solution is Brute Force<br></strong>If you absolutely *MUST* detect all keyboard input, including up to 4 simultaneous keypresses or more, you have to accept the performance trade off of checking every key’s state every Update() frame.</p><p>It is probably best to use a for loop rather than a foreach loop to regain some of the lost performance.</p><p>For the details on how I came to this conclusion, please read on.</p><p><strong>Summary<br></strong>In this article I want to briefly cover an issue I ran into while working with the new input system.</p><p>But first, why was I using the “Any key” binding in the first place?</p><p>I thought that this binding would pass the name of the key pressed.</p><p>It did not.</p><p>What was the alternative then?<br>Bind every key individually?<br> <br>Yep, but that still had issues with simultaneous keypresses and their button states registering.</p><p>So that ended my attempts to address simultaneous keypress input through the Input Action Asset.</p><p>From now on, it would be code only using the new Input System’s functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*IsAK0VaMVwkmFgELzAen1w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*2Hc4Whw6jLx-YLT0pksDNA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*PfGMdLaHyVMHacEHwJp4eg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*I5KTlpKX2ARxNYpY5sjfRw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*1xxlrXpceJ6Mm_ciRSeEkQ.png" /></figure><p><strong>The Event Driven Input Actions Asset Approach<br></strong>I originally took the Input Actions Asset approach with an Action that was bound to “Any key” for detecting all keyboard input.</p><p>Apologies that I don’t have a screenshot of the Input Actions Asset in the Unity Editor, but the related code is shown above.</p><p>This is where the issue first cropped up.<br> <br>You cannot get what key was pressed from an “Any Key” binding in the Input Actions Asset.</p><p>The InputAction.CallbackContext simply does not pass the name of the key when the binding is “Any key”.</p><p>Why, Unity, why?!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*KH_NDqiCZrRvIr7jVVqd7g.png" /></figure><p>So, as a workaround, when the “Any Key” binding was triggered in the Input Actions Asset, I checked what key was pressed that frame by checking literally every key with a foreach loop.</p><p>While this worked for one key at a time or maybe two simultaneously, anything beyond that started to miss either button phase events (Start, Cancelled) or entire buttons.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oQILCZK4TsxxKKixhLRGYA.png" /></figure><p>The results were as shown above.</p><p>When pressing Y, U, I, and O keys simultaneously, the debug logs from the InputDataCollection class only showed that Y was pressed (started) and that O was released (cancelled).<br> <br>It missed a button state for both of the 2 keys it did register, and it didn’t register 2 other keys entirely!</p><p>This can be seen by the debug logs being reported of keypresses from the old Input System class that was being phased out for the new Input System.</p><p>Note that the old input system did not report released / canceled states so we only get logs of the keypress in general for comparison’s sake.</p><p>The new input system debug logs are shown as full width above, while the old input system starts with “OnKeyPressDown”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*IqR1ABZ5NJx-bL-v6sBrdA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*tyKzBdLP30_BG7YrxM5XqQ.png" /></figure><p><strong>The Update() Approach with “Any key”<br></strong>At this point, I was still hoping to make use of the “Any key” as a trigger in order to avoid checking all keypress input on frames when none has occurred.</p><p>Using “Keyboard.current” functionality from the new Input System, I checked the “Any key” every Update() frame.</p><p>This had the same issues shown in the debug logs earlier in this article with hit or miss detection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*uIrlrwbp2yTcy17JDMC7pA.png" /></figure><p><strong>Testing the Check Every Key Every Update() Frame Approach<br></strong>At this point I tested whether individual checking every Update() frame would correctly report simultaneous input.</p><p>I had avoided this up until now with the hopes of not impacting performance with so many keypress checks since one of my use-case requirements is getting literally all keypress input on any keyboard.</p><p>For this testing though, I only set up the Y, U, I, and O keys which I then tested with simultaneous keypresses.</p><p>This worked!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/331/1*dRnnnKumtCoOthlSob0q-g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*p9FSixDBM16pi4oMRv3N5A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/1*w7c-W34J5OY4AKtw8Sk_tg.png" /></figure><p><strong>Sometimes Brute Force is What it Takes<br></strong>As mentioned at the beginning of this article, when you absolutely have to catch all keyboard input including simultaneous input of up to 4 keys (perhaps more), than you just have to bite the performance bullet.</p><p>Keyboard.current functions from the new Input System do the trick, but only have to button states.</p><p>These are pressed and released which correlate to Started and Canceled when using the Input Action Asset’s bindings.</p><p>I hope this saves someone else a day or more’s work trying to work out issues with simultaneous keypress tracking!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e436226d4818" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating Rewarded Video Ads in Unity 2021]]></title>
            <link>https://gamedevdustin.medium.com/creating-rewarded-video-ads-in-unity-2021-e42efde9523d?source=rss-e6424952cb6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e42efde9523d</guid>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[unity-development]]></category>
            <category><![CDATA[unity3d]]></category>
            <dc:creator><![CDATA[GameDev Dustin]]></dc:creator>
            <pubDate>Mon, 12 Jun 2023 01:28:39 GMT</pubDate>
            <atom:updated>2023-06-12T01:28:39.056Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*C65LtJx5fjELW_qGrTwJiw.gif" /></figure><p><strong>Summary<br></strong>In this article we’ll really roll up our sleeves and get to work on implementing Unity’s Legacy Ad system with Rewarded Ads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/263/1*Nz688E4mQq7eq-uxTtjssg.png" /></figure><p>Back in the Unity Editor, let’s create an empty gamoeobject in the Hierarchy window and name it “Ads Manager”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*c7HstpqgEJQmD6dLFXOYVg.gif" /></figure><p>Now create a new C# script called “AdsManager” and assign it as a component to our Ads Manager gameobject.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*sORqUh-zZ0SFUnHNXglHow.png" /></figure><p><strong>The AdsManager Class<br></strong>For now, we’ll just add a public method called “ShowRewardedAd” to our new AdsManager class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*rzJHteTmWM3ohOU9muQmYA.gif" /></figure><p>Now, make sure the Watch_Ad UI element has the button component.<br> <br>If not, add it as shown above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eXR4tt1_FGSF8dBlVCAKww.gif" /></figure><p>Now add an event to the OnClick() section.</p><p>Assign the Ads Manager gameobject to it.<br> <br>Then select the AdsManager class and ShowRewardedAd() method as shown above.</p><p>Now when the Watch_Ad button is clicked, ShowRewardedAd() will be called.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*H-Os3633L8bSi6qNQb6tHw.png" /></figure><p>Before we continue, just verify in the Package Manager &gt; Unity Registry that “Advertisement Legacy” is installed in your project.</p><p><strong>Get Your Game ID<br></strong>Back on the Unity Gaming Services website under the Monetization &gt; Settings tabs and Game IDs section, write down your Google Play Store ID.</p><p><a href="https://docs.unity.com/ads/en/manual/InitializingTheUnitySDK">Initializing the SDK in Unity</a></p><p><strong>Initializing Advertisements<br></strong>The above link to Unity’s Documentation gives us the code logic we need to initialize Legacy Ads.<br> <br>Reference it as needed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*Cqrb3Lmh52fktM8h9rAGlg.png" /></figure><p>Add the above code logic per Unity’s website.<br> <br>Make sure to implement the IUnityAdsInitializationListener interface and to add the using statement for UnityEngine.Advertisements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*ArSjDHwxx3LAp74e27kAfw.png" /></figure><p>On the AdsManager component, enter your Android Game ID.</p><p>Click run and you should get a successful message in the console.</p><p><a href="https://docs.unity.com/ads/en/manual/ImplementingRewardedAdsUnity">Implementing rewarded ads in Unity</a></p><p><strong>Implementing Rewarded Ads Code Logic<br></strong>As always, the ultimate authority is Unity’s own documentation.<br> <br>Reference the link above as needed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/931/1*zrGasx8c0i9EdM_P3Bd4gw.png" /></figure><p>We could separate this logic out into another class, but for this project we’ll do it all here.</p><p>Implement the IUnityAdsLoadListener and IUnityAdsShowLisetner interfaces in the AdsManager class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*VXGGasYF25xx5_gMwVhvIQ.png" /></figure><p>Then implement their associated members.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*6FDBjklyqM6rwfZ_qiAZCA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*fUr4sVtdAAyAYeZSTqsDcQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*b4HOBYXyqpdrGz77IpGvZw.png" /></figure><p><strong>Skipping to the Finish Line<br></strong>After some trial and error, this is the complete finished AdsManager class.</p><p>Most of this is identical to the Unity Documentation.</p><p>It’s actually a pretty concise way to implement this functionality with Unity’s Advertisement package handling nearly all of the logic in the background.</p><p>We do want to add some class variable references to the PlayerInventory class in order to reward diamonds after the ad has completed.</p><p>This is done in the GivePlayerReward() method which is called from OnUnityAdsShowComplete().</p><p>One major thing I’d like to not is that you will need additional functionality if you want this to happen immediately on scene load.<br> <br>When attempting to run this with the Store UI toggled on from the Editor just for testing purposes, you end up with the Advertisement initialization not having completed and it seems to just bug out from there.<br> <br>When running it in normal gameplay mode, the player takes some time to get to the store and by then the functionality is running as expected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*O_tkfQYXcl7as6TZW--fWQ.png" /></figure><p><strong>The UIManager Class<br></strong>We always want an add to load when the Store UI dialog opens.<br> <br>To do this we need a references to the AdsManager class and to call the LoadAd() method when OnShopOpen() is called.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*KNVp-lWY5wAMhg8XHl8a8g.gif" /></figure><p>Assign the AdsManager script component to the UI Manager component as shown above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/695/1*n8vWKtz4rtkQK9BqVvTJ_w.png" /></figure><p>On the Ads Manager component, make sure you’ve assigned the Watch_Ad button.</p><p>Also ensure that you’ve set the Android Game ID from the Unity Gaming Services website.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*oZBWyUmdUzD0gpmtLDe8Vg.png" /></figure><p>Hopefully, at this point you should be able to run it in the Editor and build to your Android device with Ads working!</p><p>If not, review the Unity Documentation and this article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*tMSpawujcrMCvRPIKQ5b1A.gif" /></figure><p>One last thing to note.</p><p>You’ll see the above when testing in the Unity Editor.<br> <br> The first image in this article was taken of the game running on an Android device.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e42efde9523d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting Up Unity’s Legacy Ads Unity 2021]]></title>
            <link>https://gamedevdustin.medium.com/setting-up-unitys-legacy-ads-unity-2021-ed552c974657?source=rss-e6424952cb6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed552c974657</guid>
            <category><![CDATA[unity-development]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[GameDev Dustin]]></dc:creator>
            <pubDate>Mon, 12 Jun 2023 01:19:26 GMT</pubDate>
            <atom:updated>2023-06-12T01:19:26.545Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*C65LtJx5fjELW_qGrTwJiw.gif" /></figure><p><strong>Summary<br></strong>In this article, we’ll set up Unity’s legacy Ad system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*akdEMKKv0AgE6RaxRdOI7A.png" /></figure><p><strong>Disclaimer<br></strong>Unity Ads is now “Unity Advertisement Legacy” and has been replaced with a more complex solution known as “Ads Mediation Package” which can be installed from the Unity Package Manager under “Unity Registry”.</p><p><strong>Why Bother with Legacy Ads?</strong></p><p>This article is for informational purposes and can be used for comparison to the new Ads Mediation Package.</p><p>Additionally, Legacy Ads is much simpler than Unity’s newer offerings.</p><p>I’m not suggesting you install it on a production project unless you have done your research on features and when support will end for Legacy Ads.<br> <br>I haven’t!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*wVo0pNgNlPgcvrMDHYQPwA.png" /></figure><p><strong>Giving Users Access to Rewarded Ads<br></strong>We’ll add a “Watch rewarded Ad” button to our Shop UI.</p><p>Here the player will be able to watch ads in exchange for diamonds which can be used to purchase items in the shop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*Bh91i81igXHUhXMBKQ1xBQ.gif" /></figure><p><strong>Unity Services<br></strong>As shown above, click the “cloud” icon in the Unity Editor and then click “Ads”.<br> <br>Alternatively, go to Project Settings &gt; Services &gt; Ads.</p><p>Select an organization your Unity account has access to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*LSgCqdugMO_v5oHM_VhEMw.png" /></figure><p>Answer the question regarding the app’s target audience.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*QUQanPvlqW7JVHso2Cv17Q.gif" /></figure><p>Now click the “OFF” button and then “Enable Test Mode” once it has loaded.</p><p>Test Mode lets us simulate ads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*DSxht6HB34MiY7pZg3xp9A.png" /></figure><p><strong>Unity Gaming Services — Monitzation (Ads)<br></strong>Log in to Unity’s Gaming Services website and select the “Monetization” tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*aHg_ARr2cBagyI4icyt9Zg.png" /></figure><p>Select the game where ads will be used.</p><p>Then click the circular “gear” icon next to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GrpFsih_qlm_WrkIlG81Bw.png" /></figure><p>Here you’ll be able to see your Project ID.</p><p>Then go back to Unity Gaming Services (should be button on the left-hand side to do so).</p><p><strong>Ads Mediation</strong></p><p>Sorry, once I figured this bit out, I couldn’t go back and screenshot it!</p><p>If like me, nearly all Monetization sub tabs are the same page with a blue button regarding “Ad Mediation” at the top, click the button.<br> <br>Then, it doesn’t really want to let you just use Unity Ads.<br> <br>Select the other setting, then select just Unity Ads and all of the Monetization tabs should unlock.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jaWH8xi3A9VY9pDHCrpUVg.png" /></figure><p>If you make a mistake, you can go to Monetization &gt; Current Project &gt; Settings and edit the “Mediation Partner” section to select only Unit Ads or mediation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*H8jjX_OJI8yWvcF4On79wQ.png" /></figure><p>If we scroll down, we can see this is also where we can get Game IDs, setup Apple and Google Store IDs, and more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wqHRv_rQQsU5HO-mBcAkQA.png" /></figure><p><strong>Ad Units<br></strong>Unity uses a term called “Ad Units” to differentiate between different types of ads.</p><p>Since we’ll be deploying a rewarded ad to Android, let’s select that one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*DPk87ds6tnHgyvc4Dg6b0A.png" /></figure><p>I personally hate when an ad starts with full volume, so I won’t do that to my players.<br>I’ve set muting to “Audio muted”.</p><p>Players will be able to unmute if they find the ad interesting.<br> <br>They will however have to watch the entire ad, so “Allow skip” is set to “No”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LAdy-pVXFqykhH9CpJ0aMw.png" /></figure><p><strong>Unity Ads Reporting<br></strong>Once you do have ads implemented in a production game, the “Unity Ads Reporting” tab will become much more interesting!</p><p>We’ll get into the nitty gritty in the next article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed552c974657" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adding Reactive Coloring to the UI for Touch Controls in Unity 2021]]></title>
            <link>https://gamedevdustin.medium.com/adding-reactive-coloring-to-the-ui-for-touch-controls-in-unity-2021-2cb1b4f41fde?source=rss-e6424952cb6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/2cb1b4f41fde</guid>
            <dc:creator><![CDATA[GameDev Dustin]]></dc:creator>
            <pubDate>Sun, 11 Jun 2023 21:29:35 GMT</pubDate>
            <atom:updated>2023-06-11T21:29:35.175Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*Y3R39D7yK31gWtGYxWp4Rw.gif" /></figure><p><strong>Summary<br></strong>In this article, we’ll add some color reactivity to our touch controls using Unity’s new Input System.</p><p><a href="https://gamedevdustin.medium.com/using-the-new-input-system-for-touch-input-in-unity-2021-bd1171b2ded">Using the New Input System for Touch Input in Unity 2021</a></p><p>We’ll be building on the work from the previous article.</p><p>Please reference it as needed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*ry4dejTmLnv6wtkWffGrTw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*QZ6-m_lNJfTfjGO-BaEShw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*MA_b0KvIGOAPbI8OcA3gLA.png" /></figure><p><strong>Where We Left Off Last Time<br></strong>In the last article, we set up our UI elements for the on-screen touch controls.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Aa8ZEBq_gS70lf8QtyQ8w.gif" /></figure><p>However, we only took the time to add the Joy_Stick UI to our Input Asset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*CdcrdSFWei4WwJs3Dx01TA.png" /></figure><p><strong>Adding Buttons to the Input Asset<br></strong>In the Input Asset, add a new Action for each button.<br> <br>Set the Action Type to “Button” and assign the same buttons as the “Control Path” in the On-Screen Button component of each UI element.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/517/1*U3WgaOb4Pa0Q5ZDfFARIWg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*Re6BaAYokGCdAN-ctM4EIw.png" /></figure><p><strong>The InputManager Class<br></strong>Let’s add some variables to our InputManager to reference our touch UI images and their various color states.</p><p>In the Unity Editor, set a light color on each UI image.<br> <br>Then on the InputManager component, use a variation of the same color for each “pressed” state.</p><p>I’ve used a really light color on the UI elements as their original colors, and a slightly brighter / saturated color for their pressed states.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/869/1*efptAwlC3nBudMR_ghF6kA.png" /></figure><p><strong>The InputManager Class Continued<br></strong>Now we’ll need to add the code logic for switching the color on each UI element.<br> <br>Create three methods similar to those shown above that take an InputAction.CallbackContext and use the context passed phase states to determine when the button started being pressed and stopped being pressed.</p><p>We can also use the logic shown in the GetUIColorsFromHUDElements() method to establish the original color on Awake().</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*bK1Rd568Qcv5XE-EN6bXIA.png" /></figure><p><strong>Use Player Input Events to Complete the Puzzle<br></strong>On the Input Manager’s Player Input component, expand Events and Character to access our newly create Actions.</p><p>Use them to call the Input Manager’s ColorUI_xxx() methods we just created.</p><p>And then, give it a try!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2cb1b4f41fde" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using the New Input System for Touch Input in Unity 2021]]></title>
            <link>https://gamedevdustin.medium.com/using-the-new-input-system-for-touch-input-in-unity-2021-bd1171b2ded?source=rss-e6424952cb6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd1171b2ded</guid>
            <category><![CDATA[unity-input-system]]></category>
            <category><![CDATA[gamedev]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[unity3d]]></category>
            <dc:creator><![CDATA[GameDev Dustin]]></dc:creator>
            <pubDate>Sun, 11 Jun 2023 17:50:04 GMT</pubDate>
            <atom:updated>2023-06-11T17:50:04.351Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*KFS-qQ7KsF5DtFL9GZDD1A.gif" /></figure><p><strong>Summary<br></strong>In this article we’ll look at how we can use Unity’s new Input System for Touch controls.</p><ul><li><a href="https://towardsdev.com/using-2d-vector-composite-for-movement-in-the-new-input-system-with-unity-2021-7c2f0976be98">Using 2D Vector Composite for Movement in the New Input System with Unity 2021</a></li><li><a href="https://towardsdev.com/using-1d-axis-composite-for-rotation-in-the-new-input-system-with-unity-2021-cc2a405423f3">Using 1D Axis Composite for Rotation in the New Input System with Unity 2021</a></li></ul><p><strong>Converting the Old Input to New Input<br></strong>To put it bluntly, we’ll be skipping this as we’ve covered implementing keyboard/mouse input with the new Input System in previous articles.</p><p>Granted, those articles are related to 3D movement but 2D movement is actually even simpler.</p><p>Since movement in this prototype is simply left and right (A key or D key), you would use a 1D Axis Composite to implement.</p><p>For a production project, I would suggest, ideally, starting with the new Input System or converting to the new Input System for any current input logic before moving on to using the new Input System for Touch input.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/1*gfMUWWo_V14lFc_VfSeu3Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*rWoljJCGFzhPer5mBVfzlQ.png" /></figure><p><strong>Integrating with Legacy Input for Player Movement<br></strong>In order to integrate with the legacy input for player movement, we’ll need to pass in float values to the Player class for the appropriate Touch input.</p><p>We’ll use one of the new Touch buttons to trigger PerformJump() while the Touch joystick will be used for movement.</p><p><a href="https://towardsdev.com/creating-the-input-asset-for-the-new-input-system-in-unity-2021-8abae6a4c652">Creating the Input Asset for the new Input System in Unity 2021</a></p><p><strong>Setting up the Input Asset<br></strong>I’ve covered creating an Input Asset in a previous article, please refer to it as needed.</p><p>For this project, I’ve simply named the Asset as “InputAsset” and created an Action Map called “Character”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*WoWumURetle_1IEuqcagtQ.gif" /></figure><p><strong>The Player Input Component<br></strong>While we don’t have to use a Player Input component with the new Input System, I’ll be using it for this project.</p><p>Create an empty gameobject which is named “InputManager” in the Hierarchy.<br> Create a new C# script called InputManager and assign it to the newly created InputManager gameobject.</p><p>On the InputManager gameobject, add the “Player Input” component as shown above.</p><p>Assign the InputAsset to the PlayerInput component and Default it to the Character Action Map.<br> <br>Set the Behavior as “Invoke Unity Events”.</p><p>Once you have created Actions for the Character Action Map, the Player Input component will display corresponding fields for each Action under “Events”.</p><p>We’ll get to that in a minute.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HmV0kAcjwtR04VYe2fFNng.png" /></figure><p><strong>Setting up the HUD UI<br></strong>We’ll need to add 3 UI images to the canvas we used in previous articles for the Shop dialog.</p><p>One image for our joystick and two for our buttons.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*Vs65afNES-XRl2Hk5sw5_A.gif" /></figure><p><strong>Adding On Screen Components to UI Elements<br></strong>We’ll need to add the On-Screen Joystick and On-Screen Button components to the UI image elements they correspond to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*ry4dejTmLnv6wtkWffGrTw.png" /></figure><p>Set the Control Path for the Joy_Stick element to be an Android Joystick. <br>You could also use a Gamepad’s joystick or D-Pad if you prefer.</p><p>Then set the Behavior as “Relative Position With Static Origin”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*QZ6-m_lNJfTfjGO-BaEShw.png" /></figure><p>For the A button element, it has been assigned to the Left Mouse Button as that is currently what controls the player’s attack.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*MA_b0KvIGOAPbI8OcA3gLA.png" /></figure><p>And for the B Button element, this has been assigned to the current jump button which is the Space key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Aa8ZEBq_gS70lf8QtyQ8w.gif" /></figure><p><strong>Create the HorizontalMove Action and Bindings<br></strong>As shown above, we need to create a new Action to represent our horizontal movement.</p><p>Give it a 1D Axis with the bindings matching our UI Joystick’s Control Path of “AndroidJoystick”.</p><p>NOTE: I ended up using Action Type “Value” rather than “Passthrough”, though the results should be the same or similar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/1*okPPJUetArOeAm9lOvXXKw.png" /></figure><p><strong>Modifying the Player Class for Touch Movement<br></strong>We’ll need a separate float value to hold our horizontal touch input, so add that as a class variable to the Player class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/1*jkROAzAwwIbavf1c5-MiDw.png" /></figure><p><strong>The TouchMoveHorizontal() Method<br></strong>We’ll then create a new method that will take in the touch input for movement and assign it to our new variable.</p><p>Since the current expected input for horizontal movement is a rounded integer, use Mathf.RoundToInt when reading the value.</p><p>Lastly, in the GetPlayerInput() method, we have to overwrite the original _horizInput value.<br> <br>Since GetPlayerInput() is called every frame and TouchMoveHorizontal() only when an event fires, the _horizInput value is most recent here.<br> <br>That is why we don’t directly assign _horizInput in the TouchMoveHorizontal() method itself.</p><p>We overwrite it after it looks for keyboard input which we know won’t exist when touch is being used and is thus safe to overwrite.</p><p>We do make sure that _horizTouchInput is not equal to 0, or we could cause issues for our keyboard build.</p><p><strong>What About the Input Manager Class?<br></strong>If this were a production project, I would move all of the input logic out of the Player class and into the InputManager class.<br> <br>Then the InputManager class would call public methods in the Player class to pass the necessary values for movement.<br> <br>Since we have this working and there is nothing new to learn while doing it that hasn’t been covered in previous articles, let’s just leave it here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*fL0BOABDcJ7lwIooaiIJ8A.png" /></figure><p><strong>Assigning PlayerInput Component’s Events<br></strong>Now to hook up our Player class’ TouchMoveHorizontal() method to the Input System.<br> <br>Go to the InputManager gameobject and select its Player Input component.<br> Expand “Events” and “Character”.<br> <br>Character is generated from our Input Asset to correspond with the Character Action Map.<br> <br>As such, it then contains events for every action it has.</p><p>In our case that is just the “HoriztonalMove” Action.</p><p>Assign the Player gameobject’s Player class and select the TouchMoveHorizontal method.</p><p>And we’re done!</p><p>Give it a try.</p><p><strong>Final Touches<br></strong>Feel free to build this and deploy it to your Android phone and play around with it.<br> <br>Most likely we’ll want to adjust the positioning of our buttons and joystick UI to more comfortable positions.<br> <br>Again, in a production environment, we’d probably want to give users the ability to move these where they like as well.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd1171b2ded" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>