<?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 Luke Duckett on Medium]]></title>
        <description><![CDATA[Stories by Luke Duckett on Medium]]></description>
        <link>https://medium.com/@lukeduckett?source=rss-4670b721a12e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*FWF0J88YvHstp2JUBECe_g.png</url>
            <title>Stories by Luke Duckett on Medium</title>
            <link>https://medium.com/@lukeduckett?source=rss-4670b721a12e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 19:03:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lukeduckett/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[Begin Mastering Unity’s UI Toolkit: Build a Stylized Main Menu from Scratch]]></title>
            <link>https://lukeduckett.medium.com/begin-mastering-unitys-ui-toolkit-build-a-stylized-main-menu-from-scratch-0ea80ec99af0?source=rss-4670b721a12e------2</link>
            <guid isPermaLink="false">https://medium.com/p/0ea80ec99af0</guid>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[unity-tips]]></category>
            <category><![CDATA[unity-tutorial]]></category>
            <category><![CDATA[gamedev]]></category>
            <category><![CDATA[ui-toolkit]]></category>
            <dc:creator><![CDATA[Luke Duckett]]></dc:creator>
            <pubDate>Tue, 11 Nov 2025 10:53:55 GMT</pubDate>
            <atom:updated>2025-11-11T11:17:54.693Z</atom:updated>
            <content:encoded><![CDATA[<p>Learn how to use UXML, USS and the UI Builder in Unity’s UI Toolkit to create a fully functional main menu with hover effects, popups and a scroll view.</p><p><em>This tutorial was tested in Unity 6000.2.9f. Check out </em><a href="https://github.com/Frozen-Phoenix-Studios/medium-articles.git"><em>GitHub for the full project</em></a><em> if you want to follow along or compare your results.</em></p><p>In this guide I’ll walk you through how to build a simple interactive main menu using Unity’s UI Toolkit, which is Unity’s modern web-inspired UI system designed to replace UGUI.</p><p>UI Toolkit takes its cues from web development and breaks UI into three layers:</p><ul><li>Structure: UXML (Similar to HTML)</li><li>Styling: USS (Similar to CSS)</li><li>Logic: C# (like JavaScript for interactivity)</li></ul><h3><strong>What You’ll Learn</strong></h3><p>By the end of this guide you’ll know how to:</p><ul><li>Set up your scene and panel settings</li><li>Create and organize UI elements with UXML</li><li>Style your interface using USS and the UI Builder*</li><li>Add hover effects to buttons</li><li>Access UI elements in code and handle button clicks</li><li>Build a Settings modal and connect it to your logic</li><li>Create a scrollable credits panel</li></ul><blockquote>*Quick Note: Unity UI Toolkit uses <strong>Unity Style Sheets (USS)</strong>, inspired by <strong>CSS</strong> in web development. We’ll touch on basic styling here but won’t go deep into CSS syntax or advanced USS topics.</blockquote><h3>Installing UI Toolkit</h3><p>Great news if you are using Unity 6.0 or newer, UI Toolkit is already installed by default.</p><p>If you’re on an older Unity version, you’ll need to manually install it via the Package Manager:</p><ol><li>Go to Window &gt; Package Manager.</li><li>Set the dropdown to Unity Registry.</li><li>Search for UI Toolkit and click Install.</li></ol><p>Once installed, Unity may prompt you to enable the new UI backends, click Yes and restart the editor.</p><p>*<em>Check the </em><a href="https://docs.unity3d.com/2020.2/Documentation/Manual/UITK-package.html"><em>Unity Manual</em></a><em> for compatibility notes if you’re working with legacy projects or the older UGUI system.</em></p><h3><strong>Set up scene</strong></h3><p>To get started, you need to set up your scene so you can see the UI changes as you go, for reference, my Game View is set to Full HD (1920x1080).</p><ol><li>Create an empty game object in your scene called “UI” and reset its position if it is not at (0,0,0), this object will hold any UI Document objects you create.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*d2yCfVKhMNEJA6UY1ZdyEQ.gif" /></figure><p>2. Create a UI Toolkit document object as a child of your UI Object by right clicking on the UI Game Object and selecting “UI Toolkit” &gt; “UI Document”. This creates a new game object with a “UI Document” Component and creates a new “Panel Settings”. Name this object MainMenu_UI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/1*0-mTDtRFRUAsvfzoxgHy5Q.gif" /></figure><h3>Adjust Panel Settings</h3><p>The Panel Setting asset is the UI Toolkits version of the Canvas and Canvas Scaler from the old UGUI system.</p><p>You are going to tweak it so your UI looks consistent across different resolutions.</p><ol><li>Select the newly created “PanelSettings” asset in “Assets” &gt; “UI ToolKit” &gt; “Panel Settings”.</li><li>Change Scale Mode to “<strong>Scale With Screen Size</strong>”.</li><li>Change Scale Mode Parameters:</li></ol><ul><li>Screen Match Mode: Match Width Or Height</li><li>Reference Resolution: your target resolution (this guide uses 1920x1080).</li><li>Match: 0.5.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*28aLa7c3pi-9eofDViMKIA.gif" /></figure><h3>Creating the UXML Document</h3><p>A UXML document defines the structure of your UI, like HTML does for a web page.</p><p>You can edit it in your code editor of choice or visually through the UI Builder, which is what I’ll show in this guide.</p><p>Let’s create your first layout file.</p><ol><li>Create a folder structure for UI, I created _UI/Main Menu.</li><li>Add a UI Document into this folder called “MainMenu” by right clicking on the folder and selecting “Create” &gt; “UI Toolkit” &gt; “UI Document (UXML)”.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*QFNmMAeWCcFsUHtA5_BAbw.gif" /></figure><h3>Set up UI Builder</h3><p>Open the UI Builder and set it up so you can see your UI as it will appear in-game.</p><ol><li>Double Click on the newly created asset to open the UI Builder.</li><li>Click the UXML document in the Hierarchy of the UI Builder then in the Inspector check the “Match Game View” checkbox</li><li>Click the “Fit viewport” under the Viewport tab.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tmjrqn3aXbcljAjg-BGrHw.gif" /></figure><h3>Create USS Document</h3><p>Now that your layout is ready, you can style it using <strong>USS </strong>(Unity Style Sheets), which is Unity&#39;s version of CSS.</p><p>USS defines how your UI elements look, from colours, spacing, fonts and layout behaviour.</p><blockquote><em>Quick note: You can directly edit styles in the .uss file, or through the UI Builder. Some components (like Progress Bars) still require direct USS editing.</em></blockquote><ol><li>In the StyleSheets section click the plus icon and select “Create New USS”.</li><li>Name it appropriately e.g “main-menu-styles”.</li><li>Save it to the appropriate UI folder (the one created earlier).</li><li>Save using “Ctrl+S”.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6_AI4Gm3T6uctUGfVaEscg.gif" /></figure><h3>Add UI elements to the UXML</h3><p>Now that you have your UXML and USS documents ready, it’s time to start building the actual main menu layout.</p><p>Adding an element to the document through the UI Builder is as simple as selecting the element and dragging it into the hierarchy.</p><p>Generally a good approach is to create a root element (a parent) with all other elements being added as children. The root element will take up 100% of the available area allowing you to change the styles more easily later on, and by default the children will stretch and share the available space, similar to how vertical layout groups worked in the old UI system.</p><p>You will create your Root, Panel, Title as well as a Play, Settings and Credits buttons. All these elements will be found in the Library section.</p><ol><li>Select “Visual Element” and drag it into the hierarchy — this element is a basic empty UI Element and can be found in the “Containers” section.</li><li>Rename this to “Root”.</li><li>Add another empty Visual Element underneath called “Panel”.</li><li>Under this add 2 more empty visual elements, one called “TitleText_Container” and the other “Button_Container”.</li><li>Under the TitleText_Container add a Label element from the controls section called TitleText_Label.</li><li>Add three Buttons Under Button_Container, named, “Play_Button”, “Settings_Button” and “Credits_Button”.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ggTDf8LOcZf1fP4_TiaoOg.gif" /></figure><p>This step is an optional one depending on how you want your main menu scene set up. You can go for a background image or leave it so you can set up part of a scene later for the background. I’ll cover this in future so for now you can just add a background element.</p><p>7. Drag one more Visual element into the hierarchy ensuring it is only a child of the “Root” object and not the “Panel”, and that it is the first child in the hierarchy.</p><p>8. Rename it to “Background_Image”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cIrE6cm7Tm_dWvgN9n43dA.gif" /></figure><h3>How to use the UI builder for styling</h3><p>Now that the structure is in place, you can style everything using USS selectors in the UI Builder.</p><p><strong>Create A Selector</strong></p><p>You are going to create a USS selector to handle the styles for most of the elements. You can start by styling the Background_Image so it covers the entire screen.</p><ol><li>Create a new USS selector class by clicking on the input box under the StyleSheets section, giving it an appropriate name e.g “.background-image” — notice Unity automatically adds the period “.” before the class name for you.</li><li>Enable class list visibility by pressing the menu button on the hierarchy tab (the three dots) and checking the “Class List” option — doing this will show that the class has been applied to your object.</li><li>Slide the new selector onto the “Background_Image’ element.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*80sJ-SRvSzhySBP_HzJtzQ.gif" /></figure><p>In my demonstration I have downloaded an image from Open Game Art from an artist named <strong>StumpyStrust </strong>to use as the background which you <a href="https://opengameart.org/content/space-background-2">can find here</a>.</p><h4><strong>Adjust Selector Settings</strong></h4><p><strong>Background Image</strong></p><ol><li>Select the “.background-image” selector and change the following settings:</li></ol><ul><li>Position/Position Mode: “Absolute”.</li><li>Size: Width 100%, Height 100%</li><li>Background/Image: To your background image</li><li>Background/Scale Mode: select what looks best for your image, I&#39;ve selected “Scale and Crop” as I want a full screen image that retains the original aspect ratio</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IGlLRQVENFXjYPj96WO7Kg.gif" /></figure><p><strong>Root and Panel</strong></p><p>1. Create a “.root” and “.panel” selector and add them to the respective elements.</p><p>2. On the “.root” selector adjust the following settings:</p><ul><li>Align/Justify Content: Center</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zfh2HQSRt1NanySzIQtapA.gif" /></figure><p>3. On the “.panel” selector adjust the following settings:</p><ul><li>Align/Justify Content: Center</li><li>Align/Align Self: Center</li><li>Align/Align Content: Center</li><li>Size/Width:75%</li><li>Size/Height: 75%</li><li>Size/Max Height:75%</li><li>Background/Colour: I&#39;ve set mine to a slightly transparent blue (0BCBFF, 175 alpha)</li><li>Border/Colour 0038FF, 255 alpha</li><li>Border/Width: 3px</li><li>Border/Radius: 15% (this is just for a rounded edge effect to the panel)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qogc7sC0AiRsZcKmitBDRw.gif" /></figure><p><strong>Title Text</strong></p><p>Now your are going to adjust the Title Text container and Label</p><ol><li>Create the selectors and add them to the appropriate elements (.title-text-container &amp; .title-text-label).</li><li>Adjust the .title-text-container to following settings:</li></ol><ul><li>Size/Width: 100%</li><li>Size/Height: 30%</li><li>Size/Max Height: 30%</li></ul><p>3. Adjust the .title-text-label to the following settings:</p><ul><li>Size/Width: 100%</li><li>Size/Height: 100%</li><li>Font/Style: Bold</li><li>Font/Size: 80px</li><li>Font/Align: center, middle</li><li>Font/Color: White</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KKo0M2ObFZIsC_jkfWBwjA.gif" /></figure><p>To adjust the text inside the label element you can click on the element in the hierarchy and adjust it under “Attributes/Text”, adjust this text to your game name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F14IsQ3DKakgTRAVKdzyyA.gif" /></figure><p><strong>Buttons and Container</strong></p><p>You can set up the buttons and container next.</p><ol><li>Create the selectors and attach to the appropriate element(.button-container, .main-menu-button), ensuring each of the buttons are using the same selector.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ymh6KsA6wlTK0sraeR38sg.gif" /></figure><p>2. Adjust the button-container to the following settings:</p><ul><li>Align/Align Items: Center</li><li>Align/Justify Content: Space evenly</li></ul><p>3. Adjust the .main-menu-button to the following settings</p><ul><li>Size/Width: 20%</li><li>Size/Height: 15%</li><li>Text/Size: 50px</li><li>Background/Color: 00FF8D, 255 alpha</li><li>Border/Colour: Black , 255 alpha</li><li>Border/Width: 3px</li><li>Border/Radius 35px</li><li>Change the text to the correct button text (“Play”, “Settings”, “Credits”), selecting the button will show the attributes section</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sBGbyia_liLS8UalIQG5PA.png" /></figure><h3>How to create hover effects on buttons</h3><p>Creating responsive UI Elements is simple with UI Toolkit, similar to CSS, USS has pseudo classes (hover, focus, etc.) which can react to specific events — <a href="https://docs.unity3d.com/6000.0/Documentation/Manual/UIE-USS-Selectors-Pseudo-Classes.html">see the docs</a>.</p><p>To create an effect where the button reacts to the player moving the mouse over it we can create a “:hover” version of our previous selectors we created, in this case “.main-menu-button:hover”. This selector is a version of your current selector on the buttons and is therefore already assigned to the element. Any changes to this selector’s style will be triggered when the user hovers their cursor over the button.</p><p>Now you can create a simple hover effect.</p><ol><li>Create the selector “.main-menu-button:hover”.</li><li>Select the selector and change the following settings</li></ol><ul><li>Text/Font Style: Bold</li><li>Text/Color: 01FE8F, 255 alpha</li><li>Background/Color: Black</li><li>Border/Color: White</li></ul><p><em>Note: Only the changes you explicitly define will apply in the hover state. Default values may appear in inspector but won’t affect the element unless changed.</em></p><p>3. In the viewport section click the preview button to activate preview mode.</p><p>4. Hover your mouse over the buttons to see the changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hs0xqXpaPopW5rZNdQQ-cQ.gif" /></figure><h3>How to access UI Document elements in code</h3><p>At this point you have your basic structure and styling set up, you can now move onto hooking up the logic.</p><p>You can set up the play button first which will just load into the game scene*.</p><p>*<em>I’ve created a small playground scene to load into called “Game” so we can see the scene change work — ensure its added to the build settings.</em></p><p>In order to see the UI you need to assign the UXML asset to the source asset field on the UI Document Component you created earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FSjaWlWCOdK2od4JbyvpiQ.gif" /></figure><p>Now that the UI Document component is correctly set up you can create your logic.</p><ol><li>Create a new script called “MainMenuManager” and attach it to the same object that has the UI Document Component.</li><li>Open the script, then the first thing you need access to is the UI Document Component, this give you access to the element of the UXML.</li><li>Set up references to your Play, Settings and Credit buttons here.</li></ol><p>3. Find the play button from the UI Document and register a click event callback.*</p><p><em>*Unfortunately UI Toolkit requires strings for query look ups, so ensure you have entered the correct name in query.</em></p><pre>using UnityEngine;<br>using UnityEngine.SceneManagement;<br>using UnityEngine.UIElements;<br><br>public class MainMenuManager : MonoBehaviour<br>{<br>    private UIDocument _uiDocument;<br>    <br>    private Button _playButton;<br>    private Button _settingsButton;<br>    private Button _creditsButton;<br><br>    private void Awake()<br>    {<br>        _uiDocument = GetComponent&lt;UIDocument&gt;();<br>        if (_uiDocument == null)<br>        {<br>            Debug.LogError(&quot;No UIDocument found on MainMenuManager.&quot;);<br>        }<br>        <br>        _playButton = _uiDocument.rootVisualElement.Q&lt;Button&gt;(&quot;Play_Button&quot;);<br>        _playButton.RegisterCallback&lt;ClickEvent&gt;(LoadGameScene);<br>    }<br><br>    private void LoadGameScene(ClickEvent evt)<br>    {<br>        SceneManager.LoadScene(&quot;Game&quot;);<br>    }<br>}</pre><p>You can then go back into the editor and test this is working.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*tmpB9WRcOCJwrGad8BIpCQ.gif" /></figure><h3><strong>Pop Up Modal</strong></h3><p>Now that you have created some simple logic lets expand on this knowledge and create a pop up element to act as your settings menu.</p><p>To create this you will need an object with an audio source and looped audio clip to act as background music in your scene.</p><p><em>I downloaded a clip from Open Game Art by an artist </em><strong><em>Nia Mi </em></strong><em>which can be </em><a href="https://opengameart.org/content/fun-background"><em>found here</em></a><em>.</em></p><ol><li>Create a SoundManager script with a public method to call to mute and unmute the sound effect and another for adjusting the volume. Use the Singleton Pattern for easy access to the script externally — for a good tutorial see <a href="https://youtube.com/shorts/olt198P5zXA?si=1gXtAUJXVaCKf6xb">Code Monkeys short on YouTube</a></li></ol><pre>using UnityEngine;<br><br>public class SoundManager : MonoBehaviour<br>{<br>    private static SoundManager _instance;<br>    <br>    public static SoundManager Instance<br>    {<br>        get<br>        {<br>            if (_instance == null)<br>            {<br>                Debug.LogError(&quot;SoundManager is null&quot;);<br>            }<br>            return _instance;<br>        }<br>    }<br>    <br>    private AudioSource _audioSource;<br>    <br>    private void Awake()<br>    {<br>        if (_instance != null &amp;&amp; _instance != this)<br>        {<br>            Destroy(gameObject);<br>            return;<br>        }<br>        <br>        _instance = this;<br>        <br>        _audioSource = GetComponent&lt;AudioSource&gt;();<br>    }<br><br>    public void ToggleMute(bool mute)<br>    {<br>        _audioSource.mute = mute;<br>    }<br><br>    public void AdjustSoundVolume(float volume)<br>    {<br>        _audioSource.volume = volume;<br>    }<br>}</pre><p>2. In the scene create an object called “SoundManager” and slide the background clip on it, this adds an audio source component on the object with the audio clip assigned to the Audio Resource field.</p><p>3. Add your background clip to the Audio Resource field and ensure “Play On Awake” and “Loop” are checked.</p><p>4. Add your SoundManager Script to this object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*ohnO4TCQsqTq6-oRC3U3lA.gif" /></figure><p>5. Create the Settings UI object in scene. You need to add a separate game object called “SettingsPopup_UI”, add a UI Document component, place this object as a child of your UI object that created earlier.</p><p>6. Change the sort order to 1, so this UI is rendered above the Main UI.</p><p>7. Create a new UXML document under Assets/_UI/Settings called “SettingsPopUp” and assign this to your UI Document Source Asset field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*qWON525ON43-W0RfGy_59w.png" /></figure><p>8. Open the UI Builder and create your USS document called “settings-popup-styles” and set up your view as you did before (Match Game View)</p><p>9. Create your structure now. We will need a Root object, a Panel as a child of the Root, then Label (“SettingsText_Label”), a Slider (“Volume_Slider”), Toggle(“Mute_Toggle”) and Button(“Ok_Button”) as children of the Panel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*zFeSiY12JWqwOHsU6iO00g.png" /></figure><p>10. Create your selectors, you’ll need “.hide”, “settings-root”, “.settings-panel”, “.settings-label”, “.settings-option” (this is to standardize the control elements text/font), “.settings-button”, “.settings-button:hover”, *“unity-slider__label”, *unity-toggle__label”</p><p><em>*Note the slider and toggle selectors are created to adjust unity base selectors which are greyed out in the hierarchy and need to be overridden to affect them, more info can be found in the </em><a href="https://docs.unity3d.com/6000.0/Documentation/Manual/UIE-uxml-element-Toggle.html#style-a-toggle"><em>Unity Docs</em></a><em>.</em></p><p>11. Assign the selectors to the appropriate objects, ensuring that the slider, toggle and ok button all have the settings-option selector added</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*TOQLRpG-Gg3yOzwNDe_Vdg.png" /></figure><p>12. Set up the selectors as following:</p><p><strong>.hide</strong></p><ul><li>Display/Display: none</li></ul><p><strong>.settings-root:</strong></p><ul><li>Align/Align Items: center</li><li>Align/Justify Content: center</li></ul><p><strong>.settings-panel:</strong></p><ul><li>Align/Justify Content: space-evenly</li><li>Size/Width: 60%</li><li>Size/Height: 40%</li><li>Size/Max Height: 40%</li><li>Background/Color: 0038FE, 255 alpha</li><li>Border/Color: White, 255 alpha</li><li>Border/Width: 5px</li><li>Border/Radius: 15px</li></ul><p><strong>.settings-label</strong></p><ul><li>Text/Font Style: bold</li><li>Text/Size: 60px</li><li>Text/Align: center, middle</li><li>Text/Colour : White, 255 alpha</li></ul><p><strong>.settings-option</strong></p><ul><li>Align/Align Self: center</li><li>Size/Width: 80%</li><li>Text/Size: 50px</li><li>Text/Color : White, 255 alpha</li></ul><p><strong>.settings-button</strong></p><ul><li>Size/Width: 30%</li><li>Size/Height: 20%</li><li>Background/Color: 00FD8F, 255 alpha</li><li>Border/Color: Black, 255 alpha</li><li>Border/Width: 3px</li><li>Border/Radius: 15px</li></ul><p><strong>.settings-button:hover</strong></p><ul><li>Text/Font Style: bold</li><li>Text/Colour: 00FD8F, 255 alpha</li><li>Background/Color: Black, 255 alpha</li><li>Border/Color: White, 255 alpha</li></ul><p><strong>.unity-slider__label</strong></p><ul><li>Font/Colour: White, 255 alpha</li></ul><p><strong>.unity-toggle__label</strong></p><ul><li>Font/Color: White, 255 alpha</li></ul><p>12. Adjust your text values to the appropriate strings in the SettingsText_Label, Volume_Slider, Mute_Toggle and Ok_Button, this is done under the Attributes section in the Inspector.</p><p>With the final result looking like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cHZRF0r8Jv7kGAWHl5EhaQ.gif" /></figure><p>13. Adjust the Slider min and max values under the Attributes settings to 0, 1 and check the fill button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ohj0ZSqlU5GeeYXgV-xeGA.gif" /></figure><h3><strong>SettingsUIManager</strong></h3><p>At this point you have now made your base main menu and should have the structure and style for the Settings Menu.</p><p>Next you need to create the SettingsUIManager script to handle the logic. This script will listen to the click events and forward them through to the Sound Manager. You also want to be able to toggle its visibility using the .hide selector you created earlier.</p><p>The SoundManager Script you created earlier will need adjusting too, you will need to expose its volume and mute states so the UI can match it on game start.</p><ol><li>Adjust the SoundManager script so it has a function that it exposes the state of mute and volume from the audio source.</li></ol><pre>using UnityEngine;<br><br>public class SoundManager : MonoBehaviour<br>{<br>    private static SoundManager _instance;<br>    <br>    public static SoundManager Instance<br>    {<br>        get<br>        {<br>            if (_instance == null)<br>            {<br>                Debug.LogError(&quot;SoundManager is null&quot;);<br>            }<br>            return _instance;<br>        }<br>    }<br>    <br>    private AudioSource _audioSource;<br>    <br>    private void Awake()<br>    {<br>        if (_instance != null &amp;&amp; _instance != this)<br>        {<br>            Destroy(gameObject);<br>            return;<br>        }<br>        <br>        _instance = this;<br>        <br>        _audioSource = GetComponent&lt;AudioSource&gt;();<br>    }<br><br>    public float GetCurrentVolume()<br>    {<br>        return _audioSource.volume;<br>    }<br><br>    public bool IsMuted()<br>    {<br>        return _audioSource.mute;<br>    }<br><br>    public void ToggleMute(bool mute)<br>    {<br>        _audioSource.mute = mute;<br>    }<br><br>    public void AdjustSoundVolume(float volume)<br>    {<br>        _audioSource.volume = volume;<br>    }<br>}</pre><p>2. Create the Settings UI Manager script.</p><pre>using UnityEngine;<br>using UnityEngine.UIElements;<br><br>public class SettingsUIManager : MonoBehaviour<br>{<br>    private static SettingsUIManager _instance;<br><br>    public static SettingsUIManager Instance<br>    {<br>        get<br>        {<br>            if (_instance == null)<br>            {<br>                Debug.LogError(&quot;SettingsUIManager is null&quot;);<br>            }<br><br>            return _instance;<br>        }<br>    }<br>    <br>    private UIDocument _uiDocument;<br>    private VisualElement _root;<br>    private Slider _volumeSlider;<br>    private Toggle _muteToggle;<br>    private Button _okButton;<br><br>    private void Awake()<br>    {<br>        if (_instance != null &amp;&amp; _instance != this)<br>        {<br>            Destroy(gameObject);<br>            return;<br>        }<br>        <br>        _instance = this;<br>        <br>        _uiDocument = GetComponent&lt;UIDocument&gt;();<br>        if (_uiDocument == null)<br>        {<br>            Debug.LogError(&quot;No UIDocument found on SettingsUIManager.&quot;);<br>        }<br>        <br>        _root = _uiDocument.rootVisualElement.Q&lt;VisualElement&gt;(&quot;Root&quot;);<br>        _volumeSlider = _root.Q&lt;Slider&gt;(&quot;Volume_Slider&quot;);<br>        _muteToggle = _root.Q&lt;Toggle&gt;(&quot;Mute_Toggle&quot;);<br>        _okButton = _root.Q&lt;Button&gt;(&quot;Ok_Button&quot;);<br><br>        _volumeSlider.RegisterValueChangedCallback(OnVolumeSliderValueChanged);<br>        _muteToggle.RegisterValueChangedCallback(OnMuteToggleValueChanged);<br>        _okButton.RegisterCallback&lt;ClickEvent&gt;(_ =&gt; SetInvisible());<br>        <br>        SetInvisible();<br>    }<br>    <br>    public void SetVisible()<br>    {<br>        _root.RemoveFromClassList(&quot;hide&quot;);<br>    }<br><br>    private void SetInvisible()<br>    {<br>        _root.AddToClassList(&quot;hide&quot;);<br>    }<br><br>    private void OnVolumeSliderValueChanged(ChangeEvent&lt;float&gt; evt)<br>    {<br>        SoundManager.Instance.AdjustSoundVolume(evt.newValue);<br>    }<br>    <br>    private void OnMuteToggleValueChanged(ChangeEvent&lt;bool&gt; evt)<br>    {<br>        SoundManager.Instance.ToggleMute(evt.newValue);<br>    }<br>}</pre><p>3. Adjust the MainMenuManager to call the SetVisible function when the settings button is pressed.</p><pre>using UnityEngine;<br>using UnityEngine.SceneManagement;<br>using UnityEngine.UIElements;<br><br>public class MainMenuManager : MonoBehaviour<br>{<br>    private UIDocument _uiDocument;<br>    <br>    private Button _playButton;<br>    private Button _settingsButton;<br>    private Button _creditsButton;<br><br>    private void Awake()<br>    {<br>        _uiDocument = GetComponent&lt;UIDocument&gt;();<br>        if (_uiDocument == null)<br>        {<br>            Debug.LogError(&quot;No UIDocument found on MainMenuManager.&quot;);<br>        }<br>        <br>        _playButton = _uiDocument.rootVisualElement.Q&lt;Button&gt;(&quot;Play_Button&quot;);<br>        _playButton.RegisterCallback&lt;ClickEvent&gt;(LoadGameScene);<br>        <br>        _settingsButton = _uiDocument.rootVisualElement.Q&lt;Button&gt;(&quot;Settings_Button&quot;);<br>        _settingsButton.RegisterCallback&lt;ClickEvent&gt;(ShowSettingsUI);<br>    }<br>    <br>    private void LoadGameScene(ClickEvent evt)<br>    {<br>        SceneManager.LoadScene(&quot;Game&quot;);<br>    }<br>    <br>    private void ShowSettingsUI(ClickEvent evt)<br>    {<br>        SettingsUIManager.Instance.SetVisible();<br>    }<br>}</pre><p>4. Add the SettingsUIManager script to the SettingsPopUp_UI Object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*UIuRC9f0eq_ZARGlZ2_HiA.png" /></figure><p>Now this is all set up you can test the functionality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OFBBPmjxVCoLJfFpdhfjzQ.gif" /></figure><h3>Create a scroll view</h3><p>At this point you have a working play button and settings menu, as the final piece of this guide you will add a basic credits pop up on a scroll view. The scroll view will be infinite so you can add as many entries as you require.</p><ol><li>Create your CreditsPopUp UXML and credits-popup-styles USS in your UI folder and set up UI builder view same as before.</li><li>Create the CreditsPopUp_UI game object add the UI Document and Source Tree Asset, set to Sort Order 1.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*PkM7mNxHWPErgGrmRKE7iA.png" /></figure><p>3. In the UXML add the following selectors:</p><p><strong>.hide</strong></p><ul><li>Display/Display: None</li></ul><p><strong>.credits-root</strong></p><ul><li>Align/Align Items: center</li><li>Align/Justify Content: center</li></ul><p><strong>.credits-panel</strong></p><ul><li>Size/width: 60%</li><li>Size/Height 50%</li><li>Size/Max Height: 50%</li><li>Background/Colour: rgb(0, 255, 217)</li><li>Border/Radius/15px</li></ul><p><strong>.credits-title-container</strong></p><ul><li>Text/Colour: Black, 255 alpha</li><li>Text/Align: center, middle</li><li>Text/Size: 80px;</li><li>Size/Height: 25%</li><li>Size/Max Height: 25%</li></ul><p><strong>.credits-scroll-view</strong></p><ul><li>Size/Height: 75%</li></ul><p><strong>.credits-credit-container</strong></p><ul><li>Flex/Flex Grow: 1</li><li>Flex/Flex Direction: row</li><li>Flex/Flex Wrap: no wrap</li><li>Align/Align Self: center</li><li>Align/Align Items: stretch</li><li>Size/Width: 95%</li><li>Size/Min Height: auto</li></ul><p><strong>.credits-credit-name-label</strong></p><ul><li>Text/Size: 36px</li><li>Text/Font Style: bold</li><li>Size/Width: 30%</li><li>Text/Align: middle-left</li><li>Text/Overflow: clip</li><li>Text/Wrap: pre-wrap</li></ul><p><strong>.credits-credit-description-label</strong></p><ul><li>Text/Size: 30px</li><li>Text/Align: middle-left</li><li>Text/Overflow: clip</li><li>Text/Wrap: pre-wrap</li><li>Size/Width: 70%</li></ul><p><strong>.credits-close-button</strong></p><ul><li>Align/Align Self: center</li><li>Size/Width: 20%</li><li>Spacing/Margin/Top: 10px</li><li>Spacing/Margin/Bottom: 10px</li><li>Background/Colour: 00FF8D, 255 alpha</li><li>Border/Colour: Black</li><li>Border/Width: 3px</li><li>Border/Radius 35px</li><li>Text/Size: 50px</li></ul><p><strong>.credits-close-button:hover</strong></p><ul><li>Text/Font Style: Bold</li><li>Text/Colour: 01FE8F, 255 alpha</li><li>Background/Color: Black</li><li>Border/Color: White</li></ul><p>4. You need the following UXML structure — adding the selectors as you go:</p><ul><li>Root — Visual Element — .credits-root</li><li>Panel — Visual Element — Child of Root — .credits-panel</li><li>TitleContainer — Visual Element — Child Of Panel — .credits-title-container</li><li>CreditsTitle_Label — Label — Child of TitleContainer</li><li>CreditsScrollView — ScrollView — Child Of Panel — .credits-scroll-view</li><li>Credit_Container — Visual Element — Child of CreditsScrollView* — .credits-credit-container</li></ul><p>*<em>Adding child elements to a scroll view automatically places them in its ‘content container’ — directly adding them to the container is not possible in the UI builder</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*s0Papp8m7SirhMGyIGZeiw.gif" /></figure><ul><li>CreditName_Label — Label — Child of Credit_Container — .credits-credit-name-label</li><li>CreditDescription_Label — Label -Child of Credit_Container — .credits-credit-description-label</li><li>Close_Button — Button — Child of Panel .credits-close-button</li></ul><p>It should end up looking like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0ZonjxiIuvBUJkGdZa7Xfg.png" /></figure><p>5. Change the labels and button text values to the appropriate values and you’ll now have the structure and styles of your credits pop up set up. You can also duplicate the Credit Container as many times as required to add new entries to the list*.</p><p><em>*In a future article I will cover auto scrolling the list and how to data bind this from json data.</em></p><p>End result will be a scrollable list with auto sizing child elements and a close button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kFHk-cpN-rsWkDPtkDi-8A.gif" /></figure><h3>CreditsUIManager</h3><p>Now that you have the structure and styles set up for your credits pop up you need to set up the manager script to handle the logic. At this point the logic is simply repeating what you have done before, you just need to hide and show the menu on button clicks.</p><ol><li>Create a script called CreditsUIManager and add it to the CreditsPopUp_UI game object.</li></ol><p>The script needs access to the UI Document, button, a public method for triggering the UI to display and a method for hiding it. Once again you can make it a singleton, as it is a manager class.</p><pre>using UnityEngine;<br>using UnityEngine.UIElements;<br><br>public class CreditsUIManager : MonoBehaviour<br>{<br>    private static CreditsUIManager _instance;<br><br>    public static CreditsUIManager Instance<br>    {<br>        get<br>        {<br>            if (_instance == null)<br>            {<br>                Debug.LogError(&quot;CreditsUIManager is null&quot;);<br>            }<br>            return _instance;<br>        }<br>    }<br>    <br>    private UIDocument _uiDocument;<br>    private VisualElement _root;<br>    private Button _closeButton;<br>    <br>    private void Awake()<br>    {<br>        if (_instance != null &amp;&amp; _instance != this)<br>        {<br>            Destroy(gameObject);<br>            return;<br>        }<br>        <br>        _instance = this;<br>        <br>        _uiDocument = GetComponent&lt;UIDocument&gt;();<br>        if (_uiDocument == null)<br>        {<br>            Debug.LogError(&quot;No UIDocument found on CreditsUIManager.&quot;);<br>        }<br><br>        _root = _uiDocument.rootVisualElement;<br>        _closeButton = _uiDocument.rootVisualElement.Q&lt;Button&gt;(&quot;Close_Button&quot;);<br>        _closeButton.RegisterCallback&lt;ClickEvent&gt;(_ =&gt; SetInvisible());<br>        <br>        SetInvisible();<br>    }<br>    <br>    public void SetVisible()<br>    {<br>        _root.RemoveFromClassList(&quot;hide&quot;);<br>    }<br>    <br>    private void SetInvisible()<br>    {<br>        _root.AddToClassList(&quot;hide&quot;);<br>    }<br>}</pre><p>2. Adjust the MainMenuManager to call the SetVisible function on the CreditsUIManager when the credits button is clicked.</p><pre>using UnityEngine;<br>using UnityEngine.SceneManagement;<br>using UnityEngine.UIElements;<br><br>public class MainMenuManager : MonoBehaviour<br>{<br>    private UIDocument _uiDocument;<br>    <br>    private Button _playButton;<br>    private Button _settingsButton;<br>    private Button _creditsButton;<br><br>    private void Awake()<br>    {<br>        _uiDocument = GetComponent&lt;UIDocument&gt;();<br>        if (_uiDocument == null)<br>        {<br>            Debug.LogError(&quot;No UIDocument found on MainMenuManager.&quot;);<br>        }<br>        <br>        _playButton = _uiDocument.rootVisualElement.Q&lt;Button&gt;(&quot;Play_Button&quot;);<br>        _playButton.RegisterCallback&lt;ClickEvent&gt;(LoadGameScene);<br>        <br>        _settingsButton = _uiDocument.rootVisualElement.Q&lt;Button&gt;(&quot;Settings_Button&quot;);<br>        _settingsButton.RegisterCallback&lt;ClickEvent&gt;(ShowSettingsUI);<br>        <br>        _creditsButton = _uiDocument.rootVisualElement.Q&lt;Button&gt;(&quot;Credits_Button&quot;);<br>        _creditsButton.RegisterCallback&lt;ClickEvent&gt;(ShowCreditsUI);<br>    }<br><br>    private void LoadGameScene(ClickEvent evt)<br>    {<br>        SceneManager.LoadScene(&quot;Game&quot;);<br>    }<br>    <br>    private void ShowSettingsUI(ClickEvent evt)<br>    {<br>        SettingsUIManager.Instance.SetVisible();<br>    }<br>    <br>    private void ShowCreditsUI(ClickEvent evt)<br>    {<br>        CreditsUIManager.Instance.SetVisible();<br>    }<br>}</pre><p>Now the logic is set up you can test your functionality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U85OdMTgB2rxIXnUrB7_1Q.gif" /></figure><h3><strong>Result</strong></h3><p>At this point you should have all your structure, styling and functionality set up. You will now have a main menu which allows you to switch scenes, change volume and display credits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xRgST-ffVJuiGfL1CglmoQ.gif" /></figure><p>That&#39;s all for now.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0ea80ec99af0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unity Quick Tip — Implementing Simple Screen Swipes on Mobile using the New Input System]]></title>
            <link>https://lukeduckett.medium.com/unity-quick-tip-implementing-simple-screen-swipes-on-mobile-using-the-new-input-system-b20123f6f04b?source=rss-4670b721a12e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b20123f6f04b</guid>
            <category><![CDATA[unity-developers]]></category>
            <category><![CDATA[untiy]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[unity-input-system]]></category>
            <category><![CDATA[touch-input]]></category>
            <dc:creator><![CDATA[Luke Duckett]]></dc:creator>
            <pubDate>Sat, 28 Oct 2023 03:30:19 GMT</pubDate>
            <atom:updated>2023-10-28T03:33:38.039Z</atom:updated>
            <content:encoded><![CDATA[<h3>Unity Quick Tip — Implementing a Simple Screen Swipe on Mobile using the New Input System</h3><p><em>This tutorial was tested in Unity 2022.3.10.</em></p><p>In this article, I will guide you through the process of implementing a screen swipe feature for mobile devices using Unity’s new Input System.</p><h4>Setting up the Input System:</h4><p>Go to Window &gt; Package Manager and ensure that “Unity Registry” is selected in the Packages dropdown.</p><p>Select “Input System” and click “Install” to install the Input System package.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WV83tKTGEc6oCFSJ80E4sg.gif" /></figure><p>Once the package is installed, you’ll receive a warning that the Input System backends need to be enabled. Click “Yes” to enable them, and this will restart your editor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*qcP_Rk8U-yJAANBW1FL2Gw.png" /></figure><h4>Configuring Input Debugger:</h4><p>Click the Options dropdown and enable “Simulate Touch Input From Mouse or Pen.”</p><p>The next step is to change the Input Debugger to “Simulate Touch Input From Mouse or Pen”. This is so we can test using the mouse in game mode to simulate touches.</p><p>Go to Window &gt; Analysis &gt; Input Debugger, then click the Options dropdown and enable “Simulate Touch Input From Mouse or Pen”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ENkRi-FXeRgpB8h9ajKbVA.gif" /></figure><p>To set up the environment for testing in the editor you can switch your game mode over to simulator and pick your device from the drop down, I have chosen the Samsung Galaxy S10+.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*veb2mjf1FMsoviFDZJ5d5A.gif" /></figure><p>We now need to set up our input actions. The plan is that we will track the delta of the finger movement, process it when the touch is complete to determine if the magnitude of the swipe is large enough for us to consider the movement as a swipe.</p><p>In your project view click the plus buttons and select “Input Actions” to create a new InputAction Asset. I called mine “PlayerControls”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SGebGmSVaQ5X0E3uEIbfQw.gif" /></figure><p>Double click on your InputActions asset to open it. We need to create a new action map by clicking the plus button, I called mine “Player”.</p><p>We now need to set up two Actions, one will handle when a touch and the other will track the delta of our finger swipe.</p><p>Change the name of the first action to “Touch” by double clicking on it.</p><p>To set up the Touch action, Under “Action” change the Action Type to “Button” if it is not already selected.</p><p>Change the binding by clicking the arrow on the Touch Action, then clicking on the Biding section &gt; Path input box &gt; Touch Screen &gt; Press.</p><p><em>Note: In Unity 2022.3.x, the Path Input Box may not respond well to clicks on the right-hand side of the window. For better results, click to the left-hand side of your selection.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*JikBeY5nBLkBtzjkH5FOLw.gif" /></figure><p>Create the Swipe Action by clicking the “+” button in the Actions area and renaming the new Action to “Swipe.”</p><p>Change the Action Type to “Value” and the Control type to “Vector 2.”</p><p>Change the binding to Touch Screen &gt; Delta, save the asset changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*Mt4bRFTOjWi5_iPcezQZNw.gif" /></figure><p>Click on your InputAsset and check the “Generate C# Class” checkbox and click “Apply”, this give us the ability to access the InputActions via script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*gasa4oDQmoylYZKVkbWKkQ.gif" /></figure><h4>Implementing the actions:</h4><p>Create a new script (e.g., SwipeTest) and open it.</p><p>You’ll need the following variables:</p><ul><li>_controls: This is where all of our input will be received from.</li><li>minimumSwipeMagnitude: The minimum magnitude the player&#39;s finger must reach before we register a swipe.</li><li>_swipeDirection: This is where we store the swipe delta direction.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*oYJEkh60gy2IsHJb2Pzo8g.png" /></figure><p>In the Start method, create a new instance of the player controls and assign it to your variable. Then, enable the Player action map and subscribe to the relevant events.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*AfOeh_xA6K97kQokwZlIhQ.png" /></figure><p>The Swipe.performed event is triggered when the delta changes due to touch screen finger movement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*y0gYtK1tJngkeQabRj7oLw.png" /></figure><p>The Touch.cancelled event is called when the player lifts their finger. You will check the magnitude of the delta (Swipe action) at this point to determine if the swipe was strong enough.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*T-287S4Qn9WcWUChOMYxvg.png" /></figure><h4>Testing the Functionality:</h4><p>To test this functionality, create a cube in the scene and attach the new script cube. In my scene, I’ve added two cubes — one to hold the initial position (which I’ve slightly shrunk) to help demonstrate the movement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*LQg16SU2-tmifBH12jDomQ.gif" /></figure><p>Now we can test our functionality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/1*Vj_VAp5QWKIEQzMUVmzd7g.gif" /><figcaption>The minimum magnitude stops the cube from moving if the swipe magnitude is too low.</figcaption></figure><p>That’s all for now.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b20123f6f04b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple functions in Unity ARcore for Android]]></title>
            <link>https://lukeduckett.medium.com/simple-functions-in-unity-arcore-for-android-4eca92cf5ddf?source=rss-4670b721a12e------2</link>
            <guid isPermaLink="false">https://medium.com/p/4eca92cf5ddf</guid>
            <category><![CDATA[unity-ar]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[unity-developers]]></category>
            <category><![CDATA[augmented-reality]]></category>
            <dc:creator><![CDATA[Luke Duckett]]></dc:creator>
            <pubDate>Mon, 01 Aug 2022 05:54:56 GMT</pubDate>
            <atom:updated>2022-08-01T05:54:56.733Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article I will go over how to do some of the basics in Unity AR, using ARCore for Android.</p><p>I will cover raycasts using the ARRaycastManager and use this to show how to show a target reticle in the centre of the user&#39;s screen if a plane is detected, instantiate an object onto a plane at the position a user taps the screen, and the centre position of the screen and at a random position on the current plane. I will then show how to interact with this object as well.</p><p>If you need help setting up the AR environment, you can follow <a href="https://lukeduckett.medium.com/getting-started-in-arcore-for-android-in-unity-ec1f618e587c">these instructions</a> or read <a href="https://lukeduckett.medium.com/common-components-and-terminology-in-unity-ar-305ec4a7b318">this article</a> about the common components and terminology you may encounter.</p><p>For reference, I am using some of the information and assets from the <a href="https://codelabs.developers.google.com/arcore-unity-ar-foundation#0">code lab</a> on the Google developer site.</p><p><strong>ARFunctionsManager</strong></p><p>I’ve created a manager class to handle our AR functions the “ARFunctionsManager”.</p><p>The first function I have created casts a ray from the centre of the screen and returns all the ray hits on the plane.</p><p>The second function uses the raycast hits from the previous function and uses them to get the current plane.</p><p>The third function uses the raycast hits to get the Pose from the centre screen on the current plane.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XmgZ1hDhan2zSuWpf4tCjA.png" /></figure><p><strong>Targeting Reticle</strong></p><p>Our first task is going to be to create a reticle. The model I am using is from the starter package from the Google Starter Package</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rYFbT8Vf4iAHnAHVGPZiyA.png" /></figure><p>The reticle is going to have a child game object for the visuals which can be deactivated if there is no current plane detected. We can then set the position of the reticle to the centre of the screen.</p><p>On our Reticle script, we call our AR Functions Manager and activate the visuals if a plane is found, then set the position object to the centre of the screen by using our get pose function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*HvyndJKK0TRiNpoXVxAjDg.png" /></figure><p>The next step is to add a new game object to house the functions manager and add the reticle to the scene then assign our components to the inspector.</p><p>We will have to assign the “ARRaycastManager” and “ARPlaneManager” to the matching variables in the “ARFunctionsManager” script and assign this script to the appropriate variable on our “Reticle” script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*QWnT_k3STJ3kX3Jjs7DyjA.gif" /></figure><p>When this is built we can see it in action.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*1gUHXCqAW3kSFJd5C2EDMA.gif" /></figure><h3><strong>Object I</strong>nstantiation</h3><p>I have prefabed a cube which I will spawn using the spawning function created below.</p><p><strong>Spawn at center screen point on the current plane</strong></p><p>This function is basically the same as the reticle function, we just instantiate our prefab at the position when a touch is detected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*IakA4JVg1Qu0DCxAucCxCg.png" /></figure><p>Which results in the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*RVUO07yYpa3cYqVpfh3ukw.gif" /></figure><p><strong>Spawn at touch point on the current plane</strong></p><p>This task is going to require us to get add a new function to the ARFunctionsManager that takes in a touch and returns a list of ARRaycastHits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*qpyGhwzYczNR581ODz-NzQ.png" /></figure><p>Then on our cube spawnner we can comment out the function that spawns the cube in the center of the screen and replace it with one that spawns at the touch point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*EvDOr7nWuT665LK5bkotig.png" /></figure><p>Which results in the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*yc7hNgOpU5qoKrZtczHF7A.gif" /></figure><p><strong>Spawn at a random point on the current plane</strong></p><p>This method is entirely from the ARCore code labs, it takes the current plane and finds a random triange within the mesh.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*XFUJupY3TWlhecVqQg0A3Q.png" /></figure><p>Which results in the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*FSJ-fT2nRxnzYPlcwmP5qA.gif" /></figure><h3><strong>Interacting with Spawned Objects</strong></h3><p>Interacting with Spawned Objects is actually performed the same in the AR space as a non AR space, I will still provide an example below.</p><p>I have changed the CubeSpawner script to place 6 random cubes on the screen to help with the example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*g_mPYjDdrMYR8KokNmk5eA.png" /></figure><p>The next script I have created will be placed directly on the cubes themselves. It will allow the user to tap them 2 times to change the colour and then the final will destroy the cube.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*negCFYQ_zDFl-p0eisYp9w.png" /></figure><p>Then I will adjust the prefab by setting the collider to a trigger,changing the material colour to green and adding our SpawnedCube script to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N8KS5Xsww4yhZpj6mJu-KQ.gif" /></figure><p>The next step is to create a script to handle input to cast rays into the screen to call the interact functions on the cube if the rays hit it. I have created a short script called InputManager to do this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/1*zKIXeqy-2ouBJYc0vVY4dg.png" /></figure><p>Make sure to create an object in scene and set up the input manager script on that object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1fSq2_dI5uZuS47tZUnqdA.gif" /></figure><p>All together gives us the following result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*S-dtL038y4IYnRlhy-zmQg.gif" /></figure><p>That’s all for now.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4eca92cf5ddf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Common components and terminology in Unity AR]]></title>
            <link>https://lukeduckett.medium.com/common-components-and-terminology-in-unity-ar-305ec4a7b318?source=rss-4670b721a12e------2</link>
            <guid isPermaLink="false">https://medium.com/p/305ec4a7b318</guid>
            <category><![CDATA[unity-augmented-reality]]></category>
            <category><![CDATA[augmented-reality]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[ar]]></category>
            <category><![CDATA[gamedevhq]]></category>
            <dc:creator><![CDATA[Luke Duckett]]></dc:creator>
            <pubDate>Sat, 30 Jul 2022 10:30:20 GMT</pubDate>
            <atom:updated>2022-07-31T23:19:02.434Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I will go over some of the common components and terminology you will come across when developing in Unitys’ AR environment.</p><p>When you set up your environment of AR development (in <a href="https://lukeduckett.medium.com/getting-started-in-arcore-for-android-in-unity-ec1f618e587c">my example</a> I set up ARcore for Android) you will have 4 game objects in the scene, each of which may have several components attached.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/1*ECJVTBGSXCoEt4xYYdS5RQ.png" /></figure><p>· <strong>AR Session Origin</strong>: this component is the parent object for the AR setup. It contains a camera and any game objects created from detected features such as planes and point clouds, which are placed inside an object called “Trackables”.</p><p>· <strong>AR Plane Manager</strong>: this component can create, update and remove game objects in response to detected surfaces.</p><p>· <strong>AR Anchor Manager</strong>: this component tracks and manages all the current anchors in the scene</p><p>· <strong>AR Raycast Manager</strong>: this component is used to raycast against trackables when they do not have a presence in the Physics world</p><p>· <strong>Anchor Creator</strong>: this component allows the creator of anchors with prefabs attached to be able to identify where the anchors are created</p><p><strong>· AR Session</strong>: this component controls the life cycle and configuration options for the AR Session. Enabling or disabling this component will start and stop the AR session.</p><h3><strong>Common Terms</strong></h3><p><strong>Session space</strong>: The space relative to the AR devices’ starting location. A device may report its position as 0,0,0 when the AR session begins. All other objects are then placed relative to this position.</p><p><strong>AR Plane/Plane</strong>: A flat surface detected by an AR device.</p><p><strong>Pose: </strong>a position and rotation in 3D space</p><p><strong>Anchor</strong>: a pose in the world which are periodically updated as an AR device&#39;s understanding of the world changes, these can be used to make objects stay in the same position and orientation in the space, object without anchors may appear to drift away from where they are originally placed</p><p><strong>Trackable</strong>: a feature in the physical environment that a device is able to track, such as a surface</p><p>That’s all for now.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=305ec4a7b318" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting started in ARcore for Android in Unity]]></title>
            <link>https://lukeduckett.medium.com/getting-started-in-arcore-for-android-in-unity-ec1f618e587c?source=rss-4670b721a12e------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec1f618e587c</guid>
            <category><![CDATA[unity-android-development]]></category>
            <category><![CDATA[ar]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[gamedevhq]]></category>
            <dc:creator><![CDATA[Luke Duckett]]></dc:creator>
            <pubDate>Fri, 29 Jul 2022 16:13:58 GMT</pubDate>
            <atom:updated>2022-07-30T11:37:29.150Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I will explain how to get started with AR development using ARcore and Unity.</p><p>To get started Unity does make it pretty easy. You can download the AR template and Unity will set most of the environment up for you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nNpScy400ZZ2onQuAXB2eQ.png" /></figure><p>There are a few things to change in order to have the environment set up correctly.</p><p>The first step is to switch over to the Android environment once your project has loaded. You can do this by going to “File” &gt; “Build Settings ”, selecting “Android” &gt; then “Switch Platform”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H-PR-WRzaVfoVo3Vq0V-Yg.gif" /></figure><p>Once Unity has compiled we can adjust our Player settings to enable and support ARCore. The build window should still be open, click “Player Settings” &gt; “Player” &gt; “Other Settings” and click the Android icon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bmonm2Guv81lSUz2A1TyiA.gif" /></figure><p>We need to ensure “Auto Graphics API” is unchecked and if “Vulkan” is listed under the “Graphics APIs” settings it needs to be removed as ARCore does not yet contain support for it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bmonm2Guv81lSUz2A1TyiA.gif" /></figure><p>We now need to provide a package name under the “Identification settings. I’m just going to add a generic one as an example “com.example.ARExample”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2Ip1-BwGZn_aUbGrZhcyXg.gif" /></figure><p>The next step is to select the minimum API level. For apps that require AR select “Android 7.0 ‘Nougat’ (API Level 24)”. If your app will have an optional AR component select “Android 4.0 ‘Ice Cream Sandwich’ (API Level 14)” or higher.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iXE0Eexg7v6FzCmId1SH7A.gif" /></figure><p>In the “Configuration settings” set the Scripting Backend to “IL2CPP”, and check the “ARM 64” checkbox under Target Architectures. This is to cover Google play requirements for 64-bit devices. You can read about this on the <a href="https://developers.google.com/ar/64bit">Google Developers website</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OcOgP8_clcS_9zp6a3pFmA.png" /></figure><p>The next step is to enable ARCore in the project settings. With the Project Settings window still open select “XR Plug-In Management”, switch to the Android tab and under the Plug-In Providers check the “ARCore” checkbox.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5vdBXn5i72ds4Vg--Nrcfg.gif" /></figure><p>We now want to ensure the AR packages are installed in our project. Go to “Window” &gt; “Package Manager” and switch the filter over to “Unity Registry”. “AR Foundation”, “ARKit XR Plugin”, “ARCore XR Plugin”, “Magic Leap XR Plugin”, “ARKit Face Tracking”, and “OpenXR Plugin” should all be installed/locked if you created your project from an AR template from Unity Hub.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s6Coqjc3tEY8OfnwP8NFQw.gif" /></figure><p>We now need to add in the Univeral Render Pipeline from the Package Manager. Find “Universal RP” on the list and click the “Install” button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*RBdtxuSYQ9Z40P2UGuG8Zw.gif" /></figure><p>Once this has been installed we need to create a “Universal Render Pipeline Asset” by right-clicking in our Project tab, in the assets folder and selecting “Create” &gt; “URP Asset (with Univeral Renderer)”.</p><p>This creates “New Universal Render Pipeline Asset” and “New Universal Render Pipeline Asset_Renderer”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C5Wu-leirUhW5dNEBP292Q.gif" /></figure><p>On the “New Universal Render Pipeline Asset_Renderer” object we want to click on the “Add Renderer Feature” button and select “AR Background Renderer Feature”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*vOu2BYbehe2V1stWjAgYMg.gif" /></figure><p>In our hierarchy we need the following objects “AR Session Origin” “AR Camera” (this will be a child of the AR Session Origin object), an AR Session and a Directional Light, I will expand on their components in my next article.</p><p>Finally, we just need to switch over our AR Camera so it is tagged as the main camera.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*USSvQzny8ENgc3qJrZwAzQ.gif" /></figure><p>From this point, the AR environment should be ready to go. If you build and run to your device your phone should receive a video feed and even can see the plane textures start to render on flat surfaces.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*0zG8zDDsn4BgejaehkYaDw.gif" /></figure><p>For my future examples, I will only be working on horizontal surfaces so I will switch over to this setting. I did this by selecting the AR Session Origin object, and under the “AR Plane Manager” component, I changed the detection mode from “Everything” to “Horizontal”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*FMsPSRCi-gXS2mN1Ms1_Rg.gif" /></figure><p>That’s all for now.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec1f618e587c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unity Cinemachine— Aiming Features]]></title>
            <link>https://lukeduckett.medium.com/unity-cinemachine-aiming-features-fc245053f071?source=rss-4670b721a12e------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc245053f071</guid>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[cinemachine]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[gamedevhq]]></category>
            <dc:creator><![CDATA[Luke Duckett]]></dc:creator>
            <pubDate>Thu, 10 Feb 2022 11:51:12 GMT</pubDate>
            <atom:updated>2022-02-10T11:51:12.836Z</atom:updated>
            <content:encoded><![CDATA[<p>In this quick article, I will go over the different aiming features available in in Unitys Cinemachine.</p><p>When you create and place a virtual camera into your scene Unity creates a game object with “CinemachineVirtualCamera” component attached (and attaches a “CinemachineBrain” component to your main camera if there is none attached”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Co8YbLhkTi2WxnPBFNT_g.gif" /></figure><p>On your virtual camera, you are able to assign an object for your camera to track by assigning it to the “Look At” reference.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*72SjETTc05q7GwnW9MqsXg.gif" /></figure><p>Assigning a value to the “Look At” field gives you access to the “Aim” settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*ABUGz3NPRTGHqIO44PZpHA.png" /></figure><p>You can set Aim property to any of the following:</p><h3><strong>Composer</strong>:</h3><p>This keeps the target in the centre of the frame and provides you with a bunch of setting you can use to offset the camera from the game object.</p><p><strong>Tracked Object Offset</strong>: You can set the Tracked Object Offset which allows you to offset the camera from the target object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S5BoJBfo4s0tG57ByHLulw.gif" /></figure><p><strong>Lookahead: </strong>This setting will adjust the camera based on the current motion of the target game object using an algorithm to calculate how far ahead to look. You can adjust the length of time to look ahead, the smoothing of the movement of the camera and finally, you can ignore the y axis when calculating the movement of the object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CJWHkBFz9xCoUbkGJCF22A.gif" /></figure><p><strong>Damping:</strong></p><p>This setting adjusts how far the object can move from center frame before the camera begins to follow. The horizontal and vertical settings can be set independently.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fC079c2Q6VZW5ec25BfgRA.gif" /></figure><p><strong>Screen x &amp; y: </strong>adjusts the center position of the dead zone on the x and y axis.</p><p><strong>Dead zone width and height: </strong>adjusts the width and height of the dead zone. The dead zone is the area in which the game object move around in without the camera moving.</p><p><strong>Soft zone width and height: </strong>adjusts the width and height of the soft zone. The soft zone is the area where the camera will move with the target game object to attempt to push it back into the dead zone, the speed/smoothness based on the damping setting.</p><p><strong>Bias X and Y: </strong>adjusts the soft zone relative to the dead zone</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0o0cUPmANl53w3JDxii4Ug.gif" /></figure><h3><strong>Group Composer:</strong></h3><p>This allows you to have multiple targets in the camera frame (generally used with a target group camera) the settings are generally the same as the composer settings.</p><p><strong>POV: </strong>this rotates the camera based on the user&#39;s input.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*AhGD6lSZZganPRv4XHXBDQ.png" /></figure><h3><strong>Same As Follow target</strong>:</h3><p>This sets the rotation of the camera to the same as the target game objects’ rotation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*kZZwCgkSydrZylcCIgjwgA.png" /></figure><h3><strong>Hard Look At</strong>:</h3><p>This keeps the look at target in the centre of the camera frame. This removes other aim settings and just keeps the object in the centre frame.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5qVwJ8UZsna3dGWkDLt9yg.gif" /></figure><p>Thats all for now.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc245053f071" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Light Probes in Unity]]></title>
            <link>https://lukeduckett.medium.com/light-probes-in-unity-e815480a700b?source=rss-4670b721a12e------2</link>
            <guid isPermaLink="false">https://medium.com/p/e815480a700b</guid>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[unity-developers]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <dc:creator><![CDATA[Luke Duckett]]></dc:creator>
            <pubDate>Wed, 19 Jan 2022 10:13:26 GMT</pubDate>
            <atom:updated>2022-01-19T10:13:26.422Z</atom:updated>
            <content:encoded><![CDATA[<p>In this short article, I will go over what light probes are and how to use them in Unity.</p><p>In Unity, baked lighting can make scenes look very visually appealing. The downside of these is that dynamic objects don&#39;t receive this lightmap data and therefore the scene can look flat and unresponsive to players.</p><p>Light probes act almost like sponges, soaking in baked light data. They then project it onto other dynamic objects in the scene almost as a way of simulating global illuminaion on the object.</p><p>To set up light probes in your scene go to your hierarchy tab, click the “+” button and select “Light” &gt; “Light Probe Group”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*Xjnsrw0Caz9Q_MOktE09gQ.gif" /></figure><p>This will add a group of 8 light probes to your scene. Move them around your scene to cover the areas you want the light to be reflected. If you want to add more probes to the group you can select multiple probes by clicking the “Edit Light Probes” button on the “Light Probe Group” component of your game object, ctrl + left-clicking on each probe, and hitting the “Duplicate” button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T7Bn7XrIDQKlPXlI9pRISQ.gif" /><figcaption>You’ll need to ensure you have static objects in your scene which actually receive the baked light data.</figcaption></figure><p>Now, what you’ll notice is that light is being projected onto your dynamic objects.</p><p>Before:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OHedowtZYZRXHksiCiAnxg.gif" /></figure><p>After:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vSGrDKqlOBFjX6EQ2WqAUQ.gif" /></figure><p>That’s all for now.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e815480a700b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Light layers in Unity HDRP]]></title>
            <link>https://lukeduckett.medium.com/light-layers-in-unity-hdrp-e76d87c6b089?source=rss-4670b721a12e------2</link>
            <guid isPermaLink="false">https://medium.com/p/e76d87c6b089</guid>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[unity-developers]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Luke Duckett]]></dc:creator>
            <pubDate>Tue, 18 Jan 2022 09:58:43 GMT</pubDate>
            <atom:updated>2022-01-18T09:58:43.644Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I will go over how to add light layers in the Unity High Definition Render Pipeline.</p><p>Light layers are a way of setting light sources to only affect specific objects in Unity, for example you can set a light on a layer and set it to effect your bug enemies only this could be great when set up with a simulated black light. This can greatly increase optimisation in your project.</p><p>The first step is to enable your light layers. In yout Project tab go to your “DefaultHDRPAsset” and under the “Lighting” dropdown check the “Light Layers” checkbox.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XbnX8SfrXA13dNyS91We2g.gif" /></figure><p>Next we want to set up a light layer, on your light source click the “More Options Button” (which looks like a gear icon) which will give you the light layer drop down. Select a layer to use, keeping in mind that you my have to deselect previous layers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XI12ntM_CuwYsrhsJubzPw.gif" /></figure><p>Now in your scene you should notice some changes with your game object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ku-Oal6-Ml6h-7CX17SDmA.gif" /></figure><p>If you wish to add objects to a light layer you can adjust this on their Mesh Renderer” component under the “Rendering Laymask Setting”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5S_iyGV5EJJwUk9Pb00eSQ.gif" /></figure><p>That’s all for now.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e76d87c6b089" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to the Layered Lit shader to mix Texture Maps in Unity HDRP]]></title>
            <link>https://lukeduckett.medium.com/how-to-the-layered-lit-shader-to-mix-texture-maps-in-unity-hdrp-a35ef9740c76?source=rss-4670b721a12e------2</link>
            <guid isPermaLink="false">https://medium.com/p/a35ef9740c76</guid>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[unity-developers]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <dc:creator><![CDATA[Luke Duckett]]></dc:creator>
            <pubDate>Mon, 17 Jan 2022 10:23:17 GMT</pubDate>
            <atom:updated>2022-01-17T10:23:17.414Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I will show you how to mix two texture maps in Unity HDRP.</p><p>In my project, I want to mix dirt and cobblestone materials on a plane to add another layer of realism to the material.</p><p>The first step is to create the new material to use as our dual material. Go to your project tab and click the “+” button then click “Material. Name your new material (I’m calling mine Light_Dirt_Stone_mat).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*1Hr2jA6Q6WjRgMttXDg1HQ.gif" /></figure><p>Next, change the Shader to “LayeredLit” by clicking the shader button and selecting “HRDP” &gt; “LayeredLit”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*vERKKlHZAo-Nr17rW3d4Vg.gif" /></figure><p>What you will notice under the surface inputs is that you’re able to change the “Layer Count” between 2 and 4. I will only use 2 textures in this example.</p><p>Under the “Layer List” add in your layer materials. I am using the stone material as my main and the dirt layer as my next layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*o1q9j6TwfdH1isoShw3V9A.gif" /></figure><p>Next, add a new “Plane” into your Hierarchy by clicking the “+” button and selecting “3D Object” &gt; “Plane” and apply your Light_Dirt_Stone_mat material to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/1*77YMkjlFpkAfyYd5IkUFLQ.gif" /></figure><p>The first thing to notice is our main texture is not the most prominent texture at this point, this is because we need to add a layer mask texture, this set where the second texture should render over the top of our main.</p><p>Download a texture to use as your mask or alternatively create a random noise texture in Photoshop as I’ll demonstrate below.</p><p>Create a new 256 by 256 texture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cll_6qGs1Mc1_JF5vFP-Tg.gif" /></figure><p>Use the paint bucket to colour your canvas black then press “ctrl” + “a” to select everything.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nhAGQZS6v93UgkIq1eaeZQ.gif" /></figure><p>Go to “Filter” &gt; “Noise” &gt; “Add Noise”. This will open up a window where you can adjust your Noise Level. Adjust the amount to something you’re comfortable with, set the “Distribution” to “Gaussian” and check the “Monochromatic” checkbox. I set my noise to 200% as I am going to use tiling to adjust the texture in Unity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*taIg4BhDzCAbyMByyzhbIg.gif" /></figure><p>Export this as a png by clicking “File” &gt; “Export” &gt; “Quick Export as PNG” and save it to your Unity Project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*SS98br_1GCAH7lGc-FShwQ.gif" /></figure><p>In Unity, go to your material and under “Surface Inputs” add your noise texture to the “Layer Mask” input and adjust your tiling and offset to get your desired effect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*12mfTCWpttT0JB6hS3pGVg.gif" /></figure><p>After adjusting the texture slightly this is the final result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dz4dKLsUzjdQDQvpFY50ng.png" /></figure><p>That’s all for now.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a35ef9740c76" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Decals in Unity]]></title>
            <link>https://lukeduckett.medium.com/using-decals-in-unity-f9f49b4a4142?source=rss-4670b721a12e------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9f49b4a4142</guid>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[untiy]]></category>
            <category><![CDATA[unity-developers]]></category>
            <category><![CDATA[gamedevhq]]></category>
            <dc:creator><![CDATA[Luke Duckett]]></dc:creator>
            <pubDate>Sun, 16 Jan 2022 00:31:05 GMT</pubDate>
            <atom:updated>2022-01-16T00:31:05.268Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I will go over Decals in Unity HDRP.</p><p>A decal is a texture that can be projected over the material, think like a sticker in photoshop, graffiti on a brick wall or blood splatter on the ground.</p><p>Adding a decal to an object in Unity is pretty straightforward. Once you have created or downloaded your texture you’ll want to add create new material. To do this go to the Project tab and click the “+” button and select material, this will create a default material, rename this appropriately.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*qb-dMtpE7cHEQ4dk_TTLkw.gif" /></figure><p>Next, you need to switch the shader to HDRP/Decal. To do this click the shader dropdown and select “HDRP” &gt; “Decal”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*KXLxvJYNVzIWhCyLGYxZ9Q.gif" /></figure><p>Now, we can add the base map, mask map and normal maps to the surface inputs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*cQHK_IMOBhBpIpEeX20zVg.gif" /></figure><p>The next step is to create a “Decal Projector” into our scene and assign our new texture. To do this click the “+” button in the Hierarchy tab and select “Rendering” &gt; “Decal Projector” then drag the newly created material into the “Material” input.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wdocutlO8tXC6ifPiu-FgQ.gif" /></figure><p>Now you can move your Decal projector around your scene and project the material over your objects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t_m_NLcnHpR8YfqIQgiIwQ.gif" /></figure><p>That&#39;s all for now.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9f49b4a4142" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>