<?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 Jared Amlin on Medium]]></title>
        <description><![CDATA[Stories by Jared Amlin on Medium]]></description>
        <link>https://medium.com/@jaredamlin?source=rss-e55fb2acfa59------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*srSkeop8KM6Ghf1Zgomh4A.png</url>
            <title>Stories by Jared Amlin on Medium</title>
            <link>https://medium.com/@jaredamlin?source=rss-e55fb2acfa59------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 01:03:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jaredamlin/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[Prototyping a Trio of Mini-Games IV: Puzzle Game]]></title>
            <link>https://medium.com/geekculture/prototyping-a-trio-of-mini-games-iv-puzzle-game-b8371f92e9fd?source=rss-e55fb2acfa59------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8371f92e9fd</guid>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[made-with-unity]]></category>
            <category><![CDATA[puzzle-game]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <dc:creator><![CDATA[Jared Amlin]]></dc:creator>
            <pubDate>Thu, 04 Jun 2026 13:18:40 GMT</pubDate>
            <atom:updated>2026-06-04T13:18:40.811Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xs7P3Am4n0hBc9ZZckYaOA.png" /></figure><p>Let’s dig into the third game in this series of mini-games, which is a <em>drag-and-drop </em>jigsaw puzzle game, only without the Bezier curved edges that come with a traditional jigsaw puzzle. The player will have to rely on their perceptive eyes to put the pieces in the right place and solve the puzzle.</p><p>What better dad joke of a game name than…<em>Dragon Drop</em>!</p><p><strong>Setup</strong></p><p>The <em>Hierarchy </em>is nice and clean with this game, only utilizing the <em>Canvas </em>with<em> UI </em>elements,<em> </em>and the <em>Puzzle Manager</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*mB7RksJNrikuRYN-hHtRnA.png" /></figure><p>The game begins with a press of the <em>Start </em>button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*s5r5ZnB6HcSBdf7q9Y_xZA.png" /></figure><p>In order to keep my <em>Hierarchy </em>clean, the <em>Puzzle Manager</em> will spawn in the <em>puzzle piece</em> prefabs and parent them to the <em>Puzzle Piece Parent </em>object. The <em>Sprites </em>used for each puzzle are stored in a <em>List </em>of <em>Puzzle Sprites</em> scriptable objects. The <em>Grid Layout Group</em> is adjusted based on how many <em>pieces </em>the current puzzle has. The <em>puzzle slot</em> prefabs are also spawned in, only invisible, and will be children of the <em>Grid Layout Group. </em>The <em>Size Multiplier</em> is used to set the overall size of the completed puzzle on the screen, no matter how many pieces or the size of the original image being used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*c25v-h6fmTgNQcj6DTLBTA.png" /></figure><p>Each <em>Puzzle Slot</em> will be assigned an <em>ID</em> when it is instantiated. This will be used to check for a match vs the puzzle piece ID being placed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*q0jTIFg9P2MKe9zLO4i9Tg.png" /></figure><p>The <em>Puzzle Piece</em> is a drag-and-drop button, which has an ID to compare with the <em>puzzle slot</em> when dropped.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*LMM2wl8dNUBZHn3JomFQHQ.png" /></figure><p>Each puzzle uses a scriptable object <em>List </em>of <em>Sprites</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*azeF8l0fAmtFlBbs1GaGGA.png" /></figure><p>To make a new puzzle, I simply select the desired <em>Sprite </em>and set the <em>Sprite Mode</em> to <em>Multiple</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*JDfGF5WAh1PrMFERyd8ibQ.png" /></figure><p>The <em>Sprite Editor</em> is used to <em>Slice </em>the image, using more slices for increased difficulties. Here is the first puzzle image slice, only using a temporary image. I will be featuring <em>Dragons </em>here, of course!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*aZPK5DoHO4pQskV8V-XPYw.png" /></figure><p>Here is the slice for a more complicated puzzle, using an image from another one of my projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wvaZDUbD2mohzMbSwX6YNQ.png" /></figure><p>I currently have three puzzles in the game for testing, with the last being an image of my late cat Mojito. Love you Momo!!! ❤</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*KctWA8TF4c2aYsdgHMrQFQ.png" /></figure><p><strong>Puzzle Slot</strong></p><p>These <em>Puzzle Slots</em> utilize Unity’s <em>Event Systems</em> and the <em>IDropHandler</em> interface to interact with the <em>Pointer Event Data</em> as other objects are dropped. When a puzzle piece is dropped, the puzzle slot can get the ID and check to see if they match, then let the puzzle piece know if it has matched or not. The event data from the <em>On Drop</em> function is also used to snap the placed piece to the same <em>position </em>as the puzzle slot.</p><p>The <em>puzzle slots</em> also subscribe to an event coming from the <em>Puzzle Manager</em> for when the game starts, which for now is really whenever you start a new puzzle.</p><p>At this point I’m just debugging with the <em>Mismatch </em>function, so it’s not needed for this to work.</p><pre>using UnityEngine;<br>using UnityEngine.EventSystems;<br><br>public class PuzzleSlot : MonoBehaviour, IDropHandler<br>{<br>    [SerializeField] private int _id;<br><br>    private void Start()<br>    {<br>        PuzzleManager.onGameStart += PuzzleManager_onGameStart;<br>    }<br>    private void OnDisable()<br>    {<br>        PuzzleManager.onGameStart -= PuzzleManager_onGameStart;<br>    }<br><br>    private void PuzzleManager_onGameStart()<br>    {<br>        Destroy(this.gameObject);<br>    }<br><br>    public void OnDrop(PointerEventData eventData)<br>    {<br>        print(&quot;Dropping puzzle piece&quot;);<br><br>        DragItem item = eventData.pointerDrag.gameObject.GetComponent&lt;DragItem&gt;();<br><br>        int id = item.ID();<br><br>        if (id == _id)<br>        {<br>            eventData.pointerDrag.transform.position = transform.position;<br>            item.Match();<br>        }<br>        else<br>        {<br>            eventData.pointerDrag.transform.position = transform.position;<br>            item.Mismatch();<br>        }<br>    }<br><br>    public void SetID(int id)<br>    {<br>        _id = id;<br>    }<br>}</pre><p><strong>Drag Item <em>(Puzzle Piece)</em></strong></p><p>The <em>puzzle pieces</em> also use the <em>Event Systems</em> namespece as well as a host of interfaces for when dragging <em>begins</em>, <em>ends </em>and is currently being <em>dragged</em>. I am also implementing the <em>IPointerDown</em> interface. Just like the <em>puzzle slot</em>, the <em>puzle piece</em> will destroy itself when a new round begins.</p><p>When you begin dragging a piece, it’s <em>color </em>will change to red. If it was a matched piece in the correct spot, it will set it’s <em>is matched</em> bool back to <em>false</em>, and then pass that along to the <em>puzzle manager</em>. While the player is dragging the piece, the <em>On Drag</em> interface comes into play to get the mouse pointer <em>position </em>so the puzzle piece can follow the cursor.</p><p>The <em>On Pointer Down</em> event is used to set the currently selected puzzle piece as the last sibling, which will bring it to the front of all puzzle pieces visually.</p><p>The most important part here for the puzzle visualization is the <em>Init </em>method. The <em>puzzle manager</em> will pass in the needed <em>Sprite</em>, <em>ID</em> and <em>Size</em> for each piece when instantiated.</p><pre>using UnityEngine;<br>using UnityEngine.UI;<br>using UnityEngine.EventSystems;<br>using System;<br><br>public class DragItem : MonoBehaviour, IDragHandler, IEndDragHandler, IBeginDragHandler, IPointerDownHandler<br>{<br>    [SerializeField] private int _id;<br>    private Image _image;<br>    private bool _isMatched = false;<br><br>    public static event Action&lt;bool&gt; onMatchCheck;<br><br>    private void Start()<br>    {<br>        PuzzleManager.onGameStart += PuzzleManager_onGameStart;<br>    }<br>    private void OnDisable()<br>    {<br>        PuzzleManager.onGameStart -= PuzzleManager_onGameStart;<br>    }<br><br>    private void PuzzleManager_onGameStart()<br>    {<br>        Destroy(this.gameObject);<br>    }<br><br>    public void OnBeginDrag(PointerEventData eventData)<br>    {<br>        print(&quot;Begin Drag&quot;);<br>        _image.color = Color.red;<br>        _image.raycastTarget = false;<br><br>        if (_isMatched)<br>        {<br>            _isMatched = false;<br>            onMatchCheck?.Invoke(_isMatched);<br>        }<br>    }<br><br>    public void OnDrag(PointerEventData eventData)<br>    {<br>        print(&quot;Dragging&quot;);<br>        transform.position = eventData.position;<br>    }<br><br>    public void OnEndDrag(PointerEventData eventData)<br>    {<br>        print(&quot;End Drag&quot;);<br>        _image.color = Color.white;<br>        _image.raycastTarget = true;<br><br>        if (!_isMatched)<br>            Mismatch();<br>    }<br><br>    public void OnPointerDown(PointerEventData eventData)<br>    {<br>        _image.transform.SetAsLastSibling();<br>    }<br><br>    public int ID()<br>    {<br>        return _id;<br>    }<br><br>    public void Init(int id, Sprite sprite, Vector2 size)<br>    {<br>        _image = GetComponent&lt;Image&gt;();<br>        _id = id;<br>        _image.sprite = sprite;<br>        _image.rectTransform.sizeDelta = size;<br>    }<br><br>    public void Mismatch()<br>    {<br>        //_image.rectTransform.localPosition = _startingPos;<br><br>        print(&quot;Mismatch. Try again.&quot;);<br>    }<br><br>    public void Match()<br>    {<br>        _isMatched = true;<br><br>        print(&quot;Match!&quot;);<br><br>        onMatchCheck?.Invoke(_isMatched);<br>    }<br>}</pre><p><strong>Puzzle Manager</strong></p><p>Ok, let’s dig into the meat and potatoes, roasted by dragon fire of course!</p><p>The <em>Puzzle Manager</em> subscribes to the <em>onMatchCheck</em> event being raised by the puzzle pieces. When a piece is matched, the matches value will increase by 1. When a matched piece is removed from a correct spot, it will decrement. If the amount of matches is the same as the amount of pieces in the puzzle, you win!</p><p>Well, maybe not just yet. The game ends if you have completed all of the puzzles in the puzzle sprites list, otherwise the next puzzle will immediately start. I will change this up quite a bit once I get into the visuals for this project.</p><p>When a new puzzle begins, a temp <em>Sprite</em> array is used to get the slice size from one of the incoming sprites. That gets stored in the temp <em>slice </em>and <em>texture height </em>variables for when the puzzle pieces come into play. This is used to calculate the needed <em>Fixed Row Count</em> for the <em>Grid Layout Group</em>. The <em>cell size</em> is calculated by dividing the <em>width </em>of the incoming <em>sprite </em>by the <em>size multiplier</em>.</p><p>The <em>puzzle slot</em> prefabs are <em>instantiated </em>in a for loop, parented to the <em>layout group</em>, and then the <em>ID</em> is set by the incrementing <em>i</em> variable.</p><p>The second for loop that handles the puzzle pieces uses the same conditions to run. I suppose I could run it all in one loop, but I wanted to keep this logic separate for now while I prototype and debug. I can already see a lot of clean up that needs to happen here, such as getting the array of sprites in a for loop like a crazy person, when I literally just got that value…ooof! Well…refactoring for later…</p><p>The <em>spawn range</em> is used to scatter the pieces when the game starts, only keeping them on the screen. Ideally, I will probably detect the current monitor setup to determine how far I can scatter them, as well as setting the size multiplier.</p><p>The <em>i</em> value of the loop assigns both the <em>ID’s</em> of the <em>puzzle slot</em> and <em>piece</em>, as well as the <em>sprite </em>of the puzzle piece. The <em>cell size</em> of the <em>layout group</em> is also passed to the new puzzle piece.</p><pre>using System.Collections.Generic;<br>using UnityEngine;<br>using UnityEngine.UI;<br>using System;<br><br>public class PuzzleManager : MonoBehaviour<br>{<br>    [SerializeField] private Transform _pieceParent;<br>    [SerializeField] private List&lt;SpriteArray&gt; _puzzleSprites;<br>    [SerializeField] private GridLayoutGroup _gridLayoutGroup;<br>    [SerializeField] private PuzzleSlot _puzzleSlotPrefab;<br>    [SerializeField] private DragItem _puzzlePiecePrefab;<br>    [SerializeField] private int _round = 0;<br>    [SerializeField] private int _matches = 0;<br>    [SerializeField] private float _sizeMultiplier = 2f;<br>    private Sprite[] _totalSprites;<br><br>    public static event Action onGameStart;<br><br>    // Start is called before the first frame update<br>    void Start()<br>    {<br>        DragItem.onMatchCheck += DragItem_onMatchCheck;<br>    }<br><br>    private void OnDisable()<br>    {<br>        DragItem.onMatchCheck -= DragItem_onMatchCheck;<br>    }<br><br>    private void DragItem_onMatchCheck(bool isMatched)<br>    {<br>        if (isMatched)<br>        {<br>            _matches++;<br>        }<br>        else<br>            _matches--;<br><br>        _totalSprites = _puzzleSprites[_round].GetSprites();<br><br>        if (_matches == _totalSprites.Length)<br>        {<br>            print(&quot;Puzzle Solved!&quot;);<br><br>            _round++;<br><br>            if (_round == _puzzleSprites.Count)<br>            {<br>                print(&quot;Game Win!!!&quot;);<br>            }<br>            else<br>            {<br>                //set the start next puzzle button active<br>                StartGame();<br>            }<br>        }<br>        else if (_matches &lt; 0 | _matches &gt; _totalSprites.Length)<br>        {<br>            print(&quot;Houston...we have a problem.&quot; + _matches);<br>        }<br>    }<br><br>    public void StartGame()<br>    {<br>        onGameStart?.Invoke();<br>        _matches = 0;<br><br>        Sprite[] spritesMeasure = _puzzleSprites[_round].GetSprites();<br>        Sprite sprite = spritesMeasure[0];<br>        float sliceHeight = sprite.rect.height;<br>        float texHeight = sprite.texture.height;<br><br>        int rows = Mathf.RoundToInt(texHeight / sliceHeight);<br><br>        _gridLayoutGroup.cellSize = new Vector2(sprite.rect.width / _sizeMultiplier, sprite.rect.height / _sizeMultiplier);<br>        _gridLayoutGroup.constraint = GridLayoutGroup.Constraint.FixedRowCount;<br>        _gridLayoutGroup.constraintCount = rows;<br><br>        <br><br>        for(int i = 0; i &lt; _puzzleSprites[_round].GetSprites().Length; i++)<br>        {<br>            PuzzleSlot slot = Instantiate(_puzzleSlotPrefab, _gridLayoutGroup.transform);<br><br>            slot.SetID(i);<br>        }<br><br>        for (int i = 0; i &lt; _puzzleSprites[_round].GetSprites().Length; i++)<br>        {<br>            Vector2 spawnRange = new Vector2(UnityEngine.Random.Range(-800, 800), UnityEngine.Random.Range(-400, 400));<br><br>            DragItem piece = Instantiate(_puzzlePiecePrefab, _pieceParent);<br><br>            Sprite[] sprites = _puzzleSprites[_round].GetSprites();<br><br>            piece.Init(i, sprites[i], _gridLayoutGroup.cellSize);<br><br>            RectTransform rect = piece.gameObject.GetComponent&lt;RectTransform&gt;();<br><br>            rect.localPosition = spawnRange;<br>        }<br>    }<br>}</pre><p><strong>Results</strong></p><p>Let’s test it out! When I press the <em>Start </em>button, the first puzzle scatters around the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*ipz7DykNsz-KaGh-mkByeg.gif" /></figure><p>Here you can see the puzzle <em>slots </em>and <em>pieces </em>in the <em>Hierarchy</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yaaUlLhwlfUcN_onqsgClg.png" /></figure><p>I am free to drag and drop puzzle pieces as I assemble the image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*Y-OXCxeO-Zcs4aCQKKfKWA.gif" /></figure><p>I will eventually have the next puzzle start with a button press, but for now the second puzzle immediately begins once you complete the first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*mVVQqZ733c3pd82sIv7eZg.gif" /></figure><p>This concludes the prototyping portion of these mini-games, so I hope you join me as I continue into visual development and audio implementation. Thanks for reading and have a great day!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8371f92e9fd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/prototyping-a-trio-of-mini-games-iv-puzzle-game-b8371f92e9fd">Prototyping a Trio of Mini-Games IV: Puzzle Game</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Prototyping a Trio of Mini-Games III: Math Battle Game]]></title>
            <link>https://jaredamlin.medium.com/prototyping-a-trio-of-mini-games-iii-math-battle-game-0db70d209ecc?source=rss-e55fb2acfa59------2</link>
            <guid isPermaLink="false">https://medium.com/p/0db70d209ecc</guid>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[made-with-unity]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <dc:creator><![CDATA[Jared Amlin]]></dc:creator>
            <pubDate>Thu, 28 May 2026 21:24:56 GMT</pubDate>
            <atom:updated>2026-05-28T21:24:56.129Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y81k3ocqEF_CdShn5bNvgA.png" /></figure><p>In my last article, I covered making a Match 2 mini-game. Let’s go somewhere more adventurous today, where the open world holds exciting dangers. This mini-game prompts the player to answer simple math problems, with elements of a turn based RPG.</p><p>Here is a most basic title screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*3FvyIMPYlGlsy03xHzb8nw.png" /></figure><p>The <em>Canvas </em>holds UI for the <em>score</em>, the <em>results </em>of your answer, the <em>math problem</em> panel and a <em>timer </em>slider. Our main hero is the blue wizard, who gains the mushroom and cactus as allies throughout the game.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Nm-GSYgEjfoZspvqgyuag.png" /></figure><p><strong>Players</strong></p><p>Each of the player objects use a <em>Player </em>script and an <em>animator </em>component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*1FH9yoYVa5Oo9IIYjQUjsA.png" /></figure><p>The Player class mostly just keeps track of health values, animation and the health UI. The setup is a simple event driven system where players attack all enemies with an AOE attack, while the mushroom brings an ally healing ability. The players react to a variety of events coming from the <em>Math Manager</em>, including damage, when the round is clear, when a round starts, and when the game is over.</p><p>When a new round starts, any dead allies will spring back to life with renewed vitality. While the ally heroes can die within a round, if the blue mage dies, it’s game over.</p><p>In hindsight I should have had the players directly passing their damage to the enemies. For this simple setup, I am passing the damage back to the manager so it can handle the visual timing between player attacks and enemies taking damage.</p><pre>using UnityEngine;<br>using UnityEngine.UI;<br>using System;<br><br>public class Player : MonoBehaviour<br>{<br>    #region Variables<br><br>    [SerializeField] private int _maxHealth;<br>    [SerializeField] private int _currentHealth;<br>    [SerializeField] private Animator _anim;<br>    [SerializeField] private int _damage;<br>    [SerializeField] private Slider _healthBar;<br>    [SerializeField] private bool _isHealing;<br>    [SerializeField] private bool _isHero;<br>    [SerializeField] private int _healPower = 20;<br>    private bool _isDead = false;<br><br>    public static event Action OnGameOver;<br>    public static event Action&lt;int&gt; OnAllyHeal;<br><br>    #endregion<br><br>    #region Init, OnDisable<br><br>    // Start is called before the first frame update<br>    void Start()<br>    {<br>        MathManager.OnPlayerDamage += MathManager_OnPlayerDamage;<br>        MathManager.OnRoundClear += MathManager_OnRoundClear;<br>        MathManager.OnGameWin += MathManager_OnGameWin;<br>        MathManager.OnRoundStart += MathManager_OnRoundStart;<br><br>        OnAllyHeal += Player_OnAllyHeal;<br><br>        _currentHealth = _maxHealth;<br>        _healthBar.value = _currentHealth;<br>    }<br><br>    private void OnDisable()<br>    {<br>        MathManager.OnPlayerDamage -= MathManager_OnPlayerDamage;<br>        MathManager.OnRoundClear -= MathManager_OnRoundClear;<br>        MathManager.OnGameWin -= MathManager_OnGameWin;<br>        MathManager.OnRoundStart -= MathManager_OnRoundStart;<br><br>        OnAllyHeal -= Player_OnAllyHeal;<br>    }<br><br>    #endregion<br><br>    #region Events<br><br>    private void MathManager_OnRoundStart()<br>    {<br>        //refresh health and animator to idle<br>        _isDead = false;<br>        _currentHealth = _maxHealth;<br>        _healthBar.value = _currentHealth;<br>        _anim.SetTrigger(&quot;Idle&quot;);<br>    }<br><br>    private void MathManager_OnGameWin()<br>    {<br>        if (!_isDead)<br>            _anim.SetTrigger(&quot;Victory&quot;);<br>    }<br><br>    private void MathManager_OnRoundClear()<br>    {<br>        if (!_isDead)<br>            _anim.SetTrigger(&quot;Victory&quot;);<br>    }<br><br>    private void Player_OnAllyHeal(int healAmount)<br>    {<br>        if (!_isDead)<br>        {<br>            _currentHealth += healAmount;<br><br>            if (_currentHealth &gt; _maxHealth)<br>                _currentHealth = _maxHealth;<br><br>            _healthBar.value = _currentHealth;<br>        }<br>    }<br><br>    private void MathManager_OnPlayerDamage(int damage)<br>    {<br>        if (!_isDead)<br>            Damage(damage);<br>    }<br><br>    #endregion<br><br>    #region Public Methods<br><br>    public int DamageAmount()<br>    {<br>        if (!_isDead)<br>        {<br>            Attack();<br><br>            if (_isHealing)<br>            {<br>                OnAllyHeal?.Invoke(_healPower);<br>            }<br><br>            return _damage;<br>        }<br>        else<br>            return 0;<br>    }<br><br>    public void Damage(int damageAmount)<br>    {<br>        _currentHealth -= damageAmount;<br>        _healthBar.value = _currentHealth;<br><br>        if (_currentHealth &lt;= 0)<br>        {<br>            _isDead = true;<br><br>            _anim.SetTrigger(&quot;Death&quot;);<br><br>            if (_isHero)<br>            {<br>                //need to check if main player is dead. <br>                OnGameOver?.Invoke();<br>            }<br>        }<br>        else<br>        {<br>            _anim.SetTrigger(&quot;Hit&quot;);<br>        }<br>    }<br><br>    public void Attack()<br>    {<br>        _anim.SetTrigger(&quot;Attack&quot;);<br>    }<br><br>    #endregion<br>}</pre><p><strong>Enemies</strong></p><p>This wee game has a small group of four different enemies, including a boss creature. I’ll show the other models later, but here is the basic grunt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2ddpCZRxZHHH50e8UqJlBg.png" /></figure><p>Similarly to the player objects, the enemies use an <em>Enemy </em>script and an <em>animator </em>component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*_zyFgUuUKhmTKZ5Gka6N2w.png" /></figure><p>So, the enemy class is very similar to the player class. It is similar enough that now in hindsight, I could have made a base class that both the player and enemy inherit from. Anyways…the enemies keep track of their health and incoming damage, and a UI health bar that uses a <em>Look At Constraint</em> to face the camera. Mostly the enemies play various animations when the main events happen, such as attacking for a wrong answer, getting hit for a correct answer, dying when you win and celebrating when you lose. They are heartless villains like that, rubbing salt into the wounds of loss.</p><pre>using UnityEngine;<br>using UnityEngine.UI;<br>using System;<br>using UnityEngine.Animations;<br><br>public class Enemy : MonoBehaviour<br>{<br>    #region Variables<br><br>    [SerializeField] private Slider _healthBar;<br>    [SerializeField] private int _maxHealth;<br>    [SerializeField] private int _currentHealth;<br>    [SerializeField] private int _damage;<br>    [SerializeField] private Animator _anim;<br>    [SerializeField] private LookAtConstraint _constraint;<br>    [SerializeField] private Canvas _canvas;<br>    [SerializeField] private bool _isHealing;<br>    [SerializeField] private bool _isDead = false;<br>    private ConstraintSource _source = new ConstraintSource();<br><br>    public static event Action&lt;Enemy&gt; OnEnemyDeath;<br>    public static event Action&lt;int&gt; OnEnemyHeal;<br><br>    #endregion<br><br>    #region Init<br><br>    // Start is called before the first frame update<br>    void Start()<br>    {<br>        _currentHealth = _maxHealth;<br>        _healthBar.value = _currentHealth;<br><br>        _source.sourceTransform = Camera.main.transform;<br>        _constraint.AddSource(_source);<br>        _canvas.worldCamera = Camera.main;<br><br>        MathManager.OnEnemyDamage += MathManager_OnEnemyDamage;<br>        MathManager.OnRoundClear += MathManager_onRoundClear;<br>        Player.OnGameOver += Player_OnGameOver;<br><br>        OnEnemyHeal += Enemy_OnEnemyHeal;<br>     }<br><br>    private void OnDisable()<br>    {<br>        MathManager.OnEnemyDamage -= MathManager_OnEnemyDamage;<br>        MathManager.OnRoundClear -= MathManager_onRoundClear;<br>        Player.OnGameOver -= Player_OnGameOver;<br>        OnEnemyHeal -= Enemy_OnEnemyHeal;<br>    }<br><br>    #endregion<br><br>    #region Events<br><br>    private void MathManager_onRoundClear()<br>    {<br>        Destroy(this.gameObject, 2f);<br>    }<br><br>    private void Enemy_OnEnemyHeal(int healAmount)<br>    {<br>        if (!_isDead)<br>        {<br>            _currentHealth += healAmount;<br><br>            if (_currentHealth &gt; _maxHealth)<br>                _currentHealth = _maxHealth;<br><br>            _healthBar.value = _currentHealth;<br>        }<br>    }<br><br>    private void Player_OnGameOver()<br>    {<br>        if (!_isDead)<br>            _anim.SetTrigger(&quot;Victory&quot;);<br>    }<br><br>    private void MathManager_OnEnemyDamage(int damage)<br>    {<br>        if (!_isDead)<br>        {<br>            Damage(damage);<br>        }<br>    }<br><br>    #endregion<br><br>    #region Public Methods<br><br>    public int GetDamage()<br>    {<br>        if (!_isDead)<br>        {<br>            Attack();<br><br>            if (_isHealing)<br>            {<br>                OnEnemyHeal?.Invoke(20);<br>            }<br><br>            return _damage;<br>        }<br>        else<br>            return 0;<br>    }<br><br>    public void Damage(int damageAmount)<br>    {<br>        if (damageAmount == 0)<br>            return;<br><br>        _currentHealth -= damageAmount;<br>        _healthBar.value = _currentHealth;<br><br>        if (_currentHealth &lt;= 0)<br>        {<br>            _isDead = true;<br>            _anim.SetTrigger(&quot;Dead&quot;);<br><br>            OnEnemyDeath?.Invoke(this);<br>        }<br>        else<br>        {<br>            _anim.SetTrigger(&quot;Hit&quot;);<br>        }<br>    }<br><br>    public void Attack()<br>    {<br>        _anim.SetTrigger(&quot;Attack&quot;);<br>    }<br><br>    #endregion<br>}</pre><p><strong>Math Manager</strong></p><p>Like my other game managers in this project, I should have broken down this one script to rule them all, into smaller helper classes. Prototyping be like that sometimes. I won’t post the scipt in it’s entirety here, as no one has the time to read through all that. I will share some relevant bits though, so here we go!</p><p>The Math Manager has UI references to update the score, the math problem, and the <em>Maths Input Field</em> class <em>(this is an older screen shot with a reference to the Input Field itself).</em> There are also references to a results text, a button to start the next round, the game win/ over panel, and a slider for timing the player answer time.</p><p>There are lists to store scriptable object data for each Round, the various math operators, player and enemy classes, waves and enemy positions for instantiation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*BapsOEXH7MYGiyEtutQgnQ.png" /></figure><p>Each round can be customized by making a new scriptable object <em>Round Data </em>and assigning it to the <em>Rounds </em>list on the <em>Math Manager</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*-FRp8ukeXlF2IrY0UBY1nQ.png" /></figure><p>The <em>Round Data</em> scriptable object holds <em>minimum </em>and <em>maximum </em>values for each number in the math problem, per operator, that can be adjusted for player difficulty.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*G6LI6nCLiut9TqJ23AmSAQ.png" /></figure><p>Here is the <em>Operator Settings</em> class and associated <em>Round Data</em> class. The <em>Math Manager</em> is ultimately looking for a <em>string </em>value to represent the <em>operator</em>, so the public <em>Operator Settings</em> will return that value based on what the designer sets in the inspector.</p><pre>using System.Collections;<br>using System.Collections.Generic;<br>using UnityEngine;<br><br>[System.Serializable]<br>public class OperatorSettings<br>{<br>    public string operatorSymbol; // &quot;+&quot;, &quot;-&quot;, &quot;x&quot;<br>    public int minValue;<br>    public int maxValue;<br>}<br><br>[CreateAssetMenu(fileName = &quot;RoundData&quot;, menuName = &quot;MathGame/RoundData&quot;)]<br>public class RoundData : ScriptableObject<br>{<br>    public List&lt;OperatorSettings&gt; settings;<br><br>    public OperatorSettings GetSettingsFor(string symbol)<br>    {<br>        return settings.Find(s =&gt; s.operatorSymbol == symbol);<br>    }<br>}</pre><p>Right now for a kids game, I only have <em>addition</em>, <em>subtraction </em>and <em>multiplication</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*HK-A44f1cP4lyvur5HJu1g.png" /></figure><p>There are three player objects that are used throughout the game. One is the main player, and the other two are allies that join the fight as the rounds progress.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*uRZYHH6nn0dDzBI6kOMDRQ.png" /></figure><p>The <em>Waves List</em> with <em>Wave </em>scriptable objects is used to fill the <em>Enemies </em>list each round, and the positions are stored for instantiating them in the correct spot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/1*gKHvYA7w7QaSD0UocFvUEQ.png" /></figure><p>The <em>Wave </em>scriptable object can be assigned by a designer in the inspector to dictate which enemies and how many are present per round.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*jdx-dEW9y_zlna_swPYlag.png" /></figure><p><strong>Maths Input Field</strong></p><p>The <em>Maths Input Field</em> class uses a <em>listener </em>for <em>On Submit</em>, which then disables the interactable on the input field, preventing multiple button presses until the problem is finished solving.</p><p>I was originally using the Unity event for<em> On Submit</em> in the <em>inspector</em>, but this ended up causing unintended issues. I learned that disabling the input field, or a parent game object visually, or via code, will automatically trigger anything in inspector for the Unity event. I had an issue where the player would press enter to trigger the submit, but then submit would call again immediately because I hide the input field. This would call the <em>Solve </em>method <em>twice </em>on my <em>Maths Manager</em>, which was hard to track down but causing some obvious issues. I was going to use the Unity UI event interface, but the documetation recommended using a <em>listener </em>instead, because the <em>input field</em> here is <em>Text Mesh Pro</em>.</p><pre>using UnityEngine;<br>using TMPro;<br><br>public class MathsInputField : MonoBehaviour<br>{<br>    private TMP_InputField _inputField;<br>    [SerializeField] private MathManager _mathManager;<br><br>    private void Awake()<br>    {<br>        _inputField = GetComponent&lt;TMP_InputField&gt;();<br><br>        _inputField.onSubmit.AddListener(OnInputSubmit);<br>    }<br><br>    private void OnInputSubmit(string text)<br>    {<br>        _inputField.interactable = false;<br><br>        _inputField.DeactivateInputField();<br><br>        _mathManager.Solve(text);<br>    }<br><br>    public void EnableInputField()<br>    {<br>        _inputField.interactable = true;<br>        _inputField.text = &quot;&quot;;<br>        _inputField.ActivateInputField();<br>    }<br><br>    public void DisableInputField()<br>    {<br>        _inputField.text = &quot;&quot;;<br><br>        _inputField.DeactivateInputField();<br>        _inputField.interactable = false;<br>    }<br>}</pre><p><strong>Return of the Math Manager</strong></p><p>Ok, let’s finally dive into some of the essential functions on the <em>Math Manager</em>. Here is a large host of variables. I honsetly should have made a designated UI manager to handle all of that functionality, but here we are for now.</p><pre>using System.Collections;<br>using System.Collections.Generic;<br>using UnityEngine;<br>using System.Globalization;<br>using UnityEngine.UI;<br>using TMPro;<br>using System;<br>using UnityEngine.SceneManagement;<br><br>public class MathManager : MonoBehaviour<br>{<br>    #region Variables<br><br>    private string _highScoreName;<br>    private int _highScore;<br>    private int _profileHighScore;<br>    private int _score;<br>    [SerializeField] private int _basePoints, _points; //inspector is using base points<br>    [SerializeField] private TMP_Text _scoreText;<br>    [SerializeField] private TMP_Text _problemText;<br>    private int _numberA, _numberB, _answer;<br>    [SerializeField] private MathsInputField _mathsInputField;<br>    [SerializeField] private GameObject _answerPanel;<br>    [SerializeField] private TMP_Text _resultsText;<br>    [SerializeField] private Button _startNextRoundButton;<br>    [SerializeField] private GameObject _gameWinPanel;<br>    [SerializeField] private Slider _timerSlider;<br>    private bool _isOutOfTime = false;<br>    private const string _addition = &quot;Addition&quot;, _subtraction = &quot;Subtraction&quot;, _multiplication = &quot;Multiplication&quot;;<br><br>    [SerializeField] private RoundData[] _rounds;<br>    [SerializeField] private string[] _operators = { &quot;+&quot;, &quot;-&quot;, &quot;x&quot; };<br><br>    [SerializeField] private List&lt;Player&gt; _players = new List&lt;Player&gt;();<br>    [SerializeField] private List&lt;Enemy&gt; _enemies = new List&lt;Enemy&gt;();<br><br>    [SerializeField] private List&lt;SpawnWave&gt; _waves = new List&lt;SpawnWave&gt;();<br>    [SerializeField] private Vector3[] _enemyPositions;<br>    private int _currentWave;<br>    private int _enemyCount;<br>    private float _animationWaitTime = 2f;<br><br>    private Quaternion _rotation = new Quaternion(0, 180, 0, 0);<br><br>    private int _currentProfileID;<br><br>    [SerializeField] private TMP_Text _highScoreText;<br>    [SerializeField] private TMP_Text _profileHighScoreText;<br><br>    private string _playerName;<br>    private const string _playerAttack = &quot;PlayerAttackRoutine&quot;;<br>    private const string _enemyAttack = &quot;EnemyAttackRoutine&quot;;<br>    private const string _timerRoutine = &quot;TimerRoutine&quot;;<br>    private const string _savedProfile = &quot;SavedProfile&quot;;<br>    private const string _highScoreKey = &quot;HighScoreMathBattle&quot;;<br>    private const string _highScoreNameKey = &quot;HighScoreMathBattleName&quot;;<br><br>    private bool _isEnemyAttacking = false;<br><br>    //public static Func&lt;int&gt; OnGetPlayerDamage;<br>    public static Func&lt;int&gt; OnGetEnemyDamage;<br><br>    public static event Action&lt;int&gt; OnEnemyDamage;<br>    public static event Action&lt;int&gt; OnPlayerDamage;<br>    public static event Action OnRoundClear;<br>    public static event Action OnGameWin;<br>    public static event Action OnRoundStart;<br><br>    #endregion<br>}</pre><p>Initialization is mainly checking <em>Player Prefs</em> for saved data, such as the current profile ID, name and any saved high score data. The <em>Maths Manager</em> also subscribes to an event coming from the <em>enemy </em>class whenever an enemy dies, as well as when the the main <em>player </em>dies and the game is over.</p><pre>#region Init<br><br>    // Start is called before the first frame update<br>    void Start()<br>    {<br>        _startNextRoundButton.gameObject.SetActive(false);<br>        _gameWinPanel.SetActive(false);<br><br>        if (PlayerPrefs.HasKey(_savedProfile)) //check for active profile<br>        {<br>            _currentProfileID = PlayerPrefs.GetInt(_savedProfile);<br><br>            string nameKey = $&quot;Profile_{_currentProfileID}_Name&quot;;<br><br>            _playerName = PlayerPrefs.GetString(nameKey);<br><br>            string profileHighScoreKey = $&quot;Profile_{_currentProfileID}_HighScoreMathBattle&quot;;<br><br>            if (PlayerPrefs.HasKey(profileHighScoreKey))<br>            {<br>                //profile high score<br>                _profileHighScore = PlayerPrefs.GetInt(profileHighScoreKey);<br>                _profileHighScoreText.text = _profileHighScore.ToString(&quot;N0&quot;, CultureInfo.InvariantCulture);<br>            }<br>            else<br>                _profileHighScoreText.text = &quot;High Score: &quot; + 0;<br>        }<br><br>        // High Score<br>        if (PlayerPrefs.HasKey(_highScoreKey) &amp;&amp; PlayerPrefs.HasKey(_highScoreNameKey))<br>        {<br>            _highScore = PlayerPrefs.GetInt(_highScoreKey);<br>            _highScoreName = PlayerPrefs.GetString(_highScoreNameKey);<br>            _highScoreText.text = _highScoreName + &quot; &quot; + _highScore.ToString(&quot;N0&quot;, CultureInfo.InvariantCulture);<br>        }<br>        else<br>            _highScoreText.text = &quot;Top High Score&quot; + 0;<br><br>        for (int i = 1; i &lt; _players.Count; i++) //deactivate the two companion players in the scene<br>        {<br>            _players[i].gameObject.SetActive(false);<br>        }<br><br>        Player.OnGameOver += Player_OnGameOver;<br>        Enemy.OnEnemyDeath += Enemy_OnEnemyDeath;<br>    }<br><br>    private void OnDisable()<br>    {<br>        Player.OnGameOver -= Player_OnGameOver;<br>        Enemy.OnEnemyDeath -= Enemy_OnEnemyDeath;<br>    }<br><br>    #endregion</pre><p>The <em>Start Round</em> function will activate allies as the rounds progress, and then spawn the enemies for the round.</p><pre>#region Start Round, Spawn Enemies, Generate Problem<br><br>    private void StartRound()<br>    {<br>        if (_currentWave == 2) //activate the Mushroom companion<br>            _players[1].gameObject.SetActive(true);<br><br>        if (_currentWave == 3) //activate the Cactus companion<br>            _players[2].gameObject.SetActive(true);<br><br>        SpawnEnemies();<br>    }</pre><p>The <em>Spawn Enemies</em> function utilizes a list to store the enemies for this round, which is determined by the <em>waves </em>scriptable object data. The enemies for the wave are <em>instantiated </em>into the correct positions and then added to the <em>list </em>of enemies.</p><pre>private void SpawnEnemies()<br>    {<br>        List&lt;GameObject&gt; spawnSequence = _waves[_currentWave].spawnSequence; //get enemies to spawn for this round<br><br>        int pos = 0;<br><br>        foreach(GameObject enemy in spawnSequence) //spawn enemies into the correct position<br>        {<br>            GameObject enemyInstance = Instantiate(enemy, _enemyPositions[pos], _rotation);<br>            _enemyCount++;<br>            pos++;<br><br>            Enemy enemyTemp = enemyInstance.GetComponent&lt;Enemy&gt;();<br><br>            if (enemyTemp != null)<br>                _enemies.Add(enemyTemp);<br>        }<br><br>        _currentWave++;<br>    }</pre><p>I gave myself a chuckle naming this <em>Generate Problem</em> function, but this is the good kind of problem generation…math problems!</p><p>I reset some values and then start the timer for the next problem. A math operator, as well as two numbers, are randomly selected. The numbers for the problem are random between their max and min values from the <em>Rounds </em>scriptable object data for the current round.</p><p>If the <em>operator </em>is <em>subtraction</em>, and the answer will result in a negative number, the two numeric values do a <em>tuple swap</em>. The <em>answer</em> is then calculated by passing the two integers and the operator into the <em>Calculate </em>method.</p><pre>private void GenerateProblem()<br>    {<br>        _answerPanel.SetActive(true);<br>        _resultsText.gameObject.SetActive(false);<br><br>        _isOutOfTime = false;<br><br>        _mathsInputField.EnableInputField();<br><br>        _timerSlider.value = _timerSlider.maxValue; //round timer<br>        StartCoroutine(_timerRoutine);<br><br>        string currentOp = _operators[UnityEngine.Random.Range(0, _operators.Length)]; //Get a random operator symbol<br>        <br>        OperatorSettings opSettings = _rounds[_currentWave - 1].GetSettingsFor(currentOp); //Get settings for current round and operator<br><br>        _numberA = UnityEngine.Random.Range(opSettings.minValue, opSettings.maxValue + 1); //Generate numbers based on operator setings<br>        _numberB = UnityEngine.Random.Range(opSettings.minValue, opSettings.maxValue + 1);<br><br>        if (currentOp == &quot;-&quot; &amp;&amp; _numberA &lt; _numberB) //Tuple Swap if subtraction so result is never negative<br>        {<br>            (_numberA, _numberB) = (_numberB, _numberA);<br>        }<br><br>        _answer = Calculate(_numberA, _numberB, currentOp); //calculate answer<br><br>        _problemText.text = $&quot;{_numberA} {currentOp} {_numberB} =&quot;;<br>    }</pre><p>The <em>Calculate </em>method runs a <em>switch </em>between the available operators, and then does the desired calculation based on the operator <em>parameter</em>. The calculated integer is then <em>returned </em>to the <em>answer </em>variable. If the operator <em>parameter </em>doesn’t exist here, the <em>return </em>will default to <em>zero</em>.</p><pre>private int Calculate(int a, int b, string op)<br>    {<br>        return op switch //change calculation based on operator<br>        {<br>            &quot;+&quot; =&gt; a + b,<br>            &quot;-&quot; =&gt; a - b,<br>            &quot;x&quot; =&gt; a * b,<br>            _ =&gt; 0<br>        };<br>    }</pre><p>When the player has submit their answer with the <em>Input Field</em>, the <em>Solve </em>method will run. If the user tries to enter an <em>empty string </em>as an answer, the return will be zero. The player entry is then <em>parsed </em>and compared to the answer variable before calling the <em>Correct Answer</em> or <em>Incorrect Answer</em> functions.</p><pre>public void Solve(string userAnswer) // called from Input Field<br>    {<br>        _isOutOfTime = false;<br><br>        StopCoroutine(_timerRoutine); //Stop the timer when an answer is entered<br><br>        if (_answerPanel.activeInHierarchy == false) //kick out if the Input Field is inactive<br>            return;<br><br>        if (userAnswer == &quot;&quot;) // don&#39;t let the user enter an empty answer. Default to zero. <br>        {<br>            userAnswer = 0.ToString();<br>        }<br><br>        if (int.TryParse(userAnswer, out int playerAnswer)) //Try Parse to get the player answer<br>        {<br>            if (playerAnswer == _answer)<br>            {<br>                CorrectAnswer();<br>            }<br>            else<br>            {<br>                IncorrectAnswer(); <br>            }<br>        }<br>        else<br>        {<br>            Debug.LogWarning(&quot;Invalid input! Please enter a number.&quot;);<br>            ParseFailedAnswer(); //this is already be limited to numbers only in the Input Field.<br>        }<br>    }</pre><p>If the player is correct, the UI display updates accordingly, points are awarded, and any active player characters will attack. I didn’t include the <em>Calculate Points</em> method here, but it uses the timer slider to give bonus points based on how fast the problem was answered. The score text utilizes the <em>System.Globalization</em> namespace to add the commas between a number every three digits as it grows. <em>(1,000 instead of 1000)</em>. Every time an answer is correct, the <em>High Score</em> method will check to see if a new high score is achieved, and if it is, save the profile data to <em>Player Prefs</em>.</p><pre>private void CorrectAnswer()<br>    {<br>        _resultsText.gameObject.SetActive(true);<br>        _resultsText.text = &quot;Correct!&quot;;<br><br>        _score += CalculatePoints();<br>        _scoreText.text = _score.ToString(&quot;N0&quot;, CultureInfo.InvariantCulture);<br><br>        HighScore();<br><br>        StartCoroutine(_playerAttack);<br>    }</pre><p>If the answer is incorrect, the player is shown the correct answer, before enemies attack.</p><pre>private void IncorrectAnswer()<br>    {<br>        StopCoroutine(_timerRoutine);<br><br>        _resultsText.gameObject.SetActive(true);<br><br>        if (_isOutOfTime)<br>        {<br>            _resultsText.text = &quot;Out of Time. The Answer is &quot; + _answer;<br>        }<br>        else<br>            _resultsText.text = &quot;Incorrect. The Answer is &quot; + _answer;<br><br>        if (_isEnemyAttacking == false)<br>            StartCoroutine(_enemyAttack);<br>    }</pre><p>The <em>Timer Routine</em> uses <em>Time.deltaTime</em> to reduce the slider <em>value</em>. Once the <em>minimum </em>slider value is reached, the time is out and the <em>Incorrect Answer</em> method is called.<em> </em>The <em>Input Field</em> is disabled so the player can’t enter a late response.</p><pre>private IEnumerator TimerRoutine() //called with const string value<br>    {<br>        while(_timerSlider.value &gt; _timerSlider.minValue)<br>        {<br>            _timerSlider.value -= Time.deltaTime;<br>            yield return null;<br>        }<br><br>        _isOutOfTime = true;<br><br>        _mathsInputField.DisableInputField();<br><br>        IncorrectAnswer();<br>    }</pre><p>Without going into the code here, I will simmarize some remaining logic. The <em>player </em>and <em>enemy </em>attack routines have each player or enemy attack in sequence, with a pause long enough for the attack animations to finish. Once the attacks are complete, a new problem is generated.</p><p>The High Score data includes an overall high score between all profiles, as well as the high score for the active profile. Let’s finally see some action!</p><p><strong>Testing</strong></p><p>Let’s test this out! Here is a correct answer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*sc-iMUQzhurTJ1q-GE1CAw.gif" /></figure><p>Uh oh…I took too long to answer this simple math problem. Back to school for this guy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*BGUbnnHm0Mk07agEbFJzGQ.gif" /></figure><p>Well, it looks like I need to work on my simple subtraction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*shVMOqzu3-AwVsnDf1ikyw.gif" /></figure><p>By round three, everyone is getting involved.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*WOYrSdpG0DlImrVtXdcxfA.gif" /></figure><p>Beware, as more enemies make for more damage. These are all AOE hits!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*U4Fy_KJpjpjVgpRhO2dt6A.gif" /></figure><p>If you made it this far, you have the patience of a saint! I’ll be excited to share the progress for this game once the visual design comes into play.</p><p>For now, I hope to see you next time where I cover my jigsaw style puzzle game. Thanks for reading and happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0db70d209ecc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Prototyping a Trio of Mini-Games II: Match Game]]></title>
            <link>https://jaredamlin.medium.com/prototyping-a-trio-of-mini-games-ii-match-game-020bc89d6841?source=rss-e55fb2acfa59------2</link>
            <guid isPermaLink="false">https://medium.com/p/020bc89d6841</guid>
            <category><![CDATA[user-interface]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[mobile-games]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[unity3d]]></category>
            <dc:creator><![CDATA[Jared Amlin]]></dc:creator>
            <pubDate>Wed, 15 Apr 2026 12:33:22 GMT</pubDate>
            <atom:updated>2026-04-16T15:20:34.974Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*772IDQpeaZ-p25odn7-J_g.png" /></figure><p>I my last article, I covered the <em>Main Menu</em> for these three mini-games. This article will take a look at the logic I setup for the <em>Match 2</em> game, tentatively called <em>‘Magic Match’.</em> Let’s get into it!</p><p><strong>Setup</strong></p><p>Here is a very simple title menu for this game. I will be doing other articles on visual design, so for now you get the basics. When you press the <em>Start </em>button, the menu will hide and the game will begin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aNtdB0mlIY-HuuJc5-fJyg.png" /></figure><p>The match tiles are instantiating into the <em>Grid Layout Group </em>parent, for easy size and layout control. I adjust the <em>Constraint Count</em> as the game progresses and adds more tiles to match.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*RNKQTqp3A4y83ry8YlTRvw.png" /></figure><p><strong>The Match Tile</strong></p><p>The <em>Match Manager </em>is doing a lot of work in this game…probably too much. The main thing to note here is the <em>Tile Data</em> scriptable object list, which holds the data for each different tile in the game.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1021/1*bybN54sl5gixJQmdvb1RIg.png" /></figure><p>Each <em>Tile Data</em> scriptable object has an associated <em>ID</em>, <em>Name </em>and <em>Image</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*KQpHxN44tUJN6cynGlqEXg.png" /></figure><p>The <em>Tile Data</em> scriptable object has a public return for the <em>Tile</em> script<em> </em>to initialize from.</p><pre>using UnityEngine;<br><br>[CreateAssetMenu(fileName = &quot;newTileData.asset&quot;, menuName = &quot;MatchData/Tile&quot;)]<br>public class TileData : ScriptableObject<br>{<br>    [SerializeField] private int _id;<br>    [SerializeField] private string _tileName;<br>    [SerializeField] private Sprite _tileImage;<br><br>    public (int id, string name, Sprite sprite) GetTileData() =&gt; (_id, _tileName, _tileImage);<br>}</pre><p>The <em>Tile prefab</em> has a <em>Tile script </em>and a <em>Button</em>. The prefab has a cover <em>image </em>which is used to hide the tile until clicked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*XXUA_4N5j9VSGgjqgv_23w.png" /></figure><p>The <em>Tile </em>class subscribes to three events coming from the <em>Match Manager</em>. When a new round starts, the tiles from the previous round destroy themselves. The player needs a few seconds to see the tiles if there is a <em>mismatch</em>. In this case the tiles will<em> ‘lock’</em> by disabling their buttons until the delay is over, mainly to prevent button smashing. If the tile has already been <em>matched</em>, it will not unlock.</p><p>When each tile is <em>instantiated</em>, the <em>Match Manager</em> will pass in different <em>Tile Data</em> parameters for initialization. When a tile is clicked, the <em>cover </em>image will hide, the <em>button </em>will disable, and the tile will pass it’s own <em>Tile Data</em> back to the <em>Match Manager</em>.</p><p>After two tiles are selected, the <em>Match Manager</em> will let the those tiles know if they were a match or not. If matched, the <em>Is Complete</em> bool becomes <em>true</em>, and the button will <em>not </em>re-enable. If there is no match, the tile will show the <em>cover </em>image again and <em>enable </em>it’s <em>button</em>.</p><pre>using UnityEngine;<br>using UnityEngine.UI;<br>using TMPro;<br>using System;<br><br>public class Tile : MonoBehaviour<br>{<br>    [SerializeField] private int _id;<br>    [SerializeField] private Image _image;<br>    [SerializeField] private TMP_Text _text;<br>    [SerializeField] private GameObject _cover;<br>    [SerializeField] private Button _button;<br>    [SerializeField] private TileData _tileData;<br>    private bool _isComplete = false;<br><br>    public static event Action&lt;int, Tile&gt; onTileSelect;<br><br>    private void Start()<br>    {<br>        MatchManager.onRoundStart += MatchManager_onRoundStart;<br>        MatchManager.onLockTiles += MatchManager_onLockTiles;<br>        MatchManager.onUnlockTiles += MatchManager_onUnlockTiles;<br>    }<br><br>    private void OnDisable()<br>    {<br>        MatchManager.onRoundStart -= MatchManager_onRoundStart;<br>        MatchManager.onLockTiles -= MatchManager_onLockTiles;<br>        MatchManager.onUnlockTiles -= MatchManager_onUnlockTiles;<br>    }<br><br>    private void MatchManager_onUnlockTiles()<br>    {<br>        if (!_isComplete)<br>            _button.enabled = true;<br>    }<br><br>    private void MatchManager_onLockTiles()<br>    {<br>        _button.enabled = false;<br>    }<br><br>    private void MatchManager_onRoundStart()<br>    {<br>        Destroy(this.gameObject);<br>    }<br><br>    public void SetData(TileData data)<br>    {<br>        _tileData = data;<br><br>        if (_tileData != null)<br>        {<br>            var (id, tileName, sprite) = _tileData.GetTileData();<br><br>            _id = id;<br>            _text.text = tileName;<br>            _image.sprite = sprite;<br>        }<br>    }<br><br>    public void OnClick()<br>    {<br>        _button.enabled = false;<br>        _cover.SetActive(false);<br><br>        onTileSelect?.Invoke(_id, this);<br>    }<br><br>    public void OnMatchCheck(bool isMatched)<br>    {<br>        if (this == null) return;<br><br>        if (!_isComplete)<br>        {<br>            if (isMatched)<br>            {<br>                _isComplete = true;<br>            }<br>            else<br>            {<br>                _cover.SetActive(true);<br>                _button.enabled = true;<br>            }<br>        }<br>    }<br>}</pre><p><strong>Match Manager</strong></p><p>I probably should have broken this up into a UI Manager as well, but I was deep into prototyping, and such things can still be accomplished. The <em>Tile Data</em> list holds the needed information for each <em>tile</em>, and will pass that along when instantiating the tile <em>prefab</em>. The <em>Round Config</em> helper class is designer friendly, being you can enter the amount of tiles to spawn, as well as the <em>Grid Constraint </em>for the <em>Grid Layout Group </em>per round.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*09J_fx9M5ZfWk2vqKnHnyw.png" /></figure><p>Here is the <em>Round Config</em>, keeping things together visually as the game progresses.</p><pre>[System.Serializable]<br>public class RoundConfig //increase tile count and Grid Layout Group as rounds increase<br>{<br>    public int TileCount; //total tiles for current round. <br>    public int GridConstraint; //Row count for GridLayoutGroup<br>}</pre><p>I won’t bombard you with this one script to rule them all…but I will share some of the more important game logic related details. I have a host of variables for <em>scores </em>and <em>best times</em> per user, as well as between all users.</p><p>I am using <em>Linq </em>to randomize the list of tiles, which gives me some easy tile shuffling. The <em>Globalization </em>namespace is used for getting my score to have a standardized comma every three decimal places. I’m saving and loading using <em>Player Prefs</em>, so I like to cache save <em>keys </em>into constant string variables to avoid any potential typos down the line.</p><pre>using System.Collections;<br>using System.Collections.Generic;<br>using UnityEngine;<br>using UnityEngine.UI;<br>using System.Linq;<br>using System;<br>using TMPro;<br>using System.Globalization;<br><br>public class MatchManager : MonoBehaviour<br>{<br>    #region Variables<br><br>    [SerializeField] private List&lt;TileData&gt; _tileDataList; //list of each tile data scriptable object<br>    private List&lt;TileData&gt; _pairedList = new List&lt;TileData&gt;(); //duplicate list of tile data list for making matches<br>    private List&lt;TileData&gt; _shuffledList = new List&lt;TileData&gt;(); //list for shuffling all tiles before instantiating<br>    [SerializeField] private GameObject _tilePrefab; //tile prefab to spawn and assign tile data to<br>    [SerializeField] private GridLayoutGroup _layoutGroup; //spawn tiles to grid layout group and adjust columns for match count<br>    [SerializeField] private List&lt;RoundConfig&gt; _rounds; //tile count and grid constraint class at bottom of THIS class<br>    private int _matchesFound = 0; //count how many matches are found to end the round<br>    private bool _firstSelected = false; //bool for first or second tile selected<br>    private Tile _firstTile, _secondTile; //store Tile data to compare selected tiles for a match<br>    private int _a, _b; //use to compare two ID&#39;s from selected tiles<br>    private int _round; //increment rounds as game progresses. Used for increased tile count<br>    private bool _isProcessing = false; //lock out button smashing while checking for a match<br><br>    private int _score;<br>    private int _timeMultiplier, _roundTimeMultiplier; //bonus points for finishing the round quickly<br><br>    [SerializeField] private TMP_Text _scoreText;<br>    [SerializeField] private TMP_Text _roundTimeText;<br>    [SerializeField] private TMP_Text _gameTimeText;<br>    private float _startTime, _elapsedTime, _roundStartTime, _roundTime, _gameCompleteTime; //track time values<br>    private List&lt;float&gt; _roundCompleteTimes = new List&lt;float&gt;();<br><br>    [SerializeField] GameObject _nextRoundPanel;<br>    [SerializeField] GameObject _gameCompletePanel;<br><br>    public static event Action onRoundStart;<br>    public static event Action onLockTiles;<br>    public static event Action onUnlockTiles;<br><br>    private const string _highScoreKey = &quot;HighScoreMatch&quot;;<br>    private const string _highScoreNameKey = &quot;HighScoreMatchName&quot;;<br>    private const string _fastestTimeKey = &quot;FastestTimeMatch&quot;;<br>    private const string _fastestTimeNameKey = &quot;FastestTimeMatchName&quot;;<br>    private const string _savedProfile = &quot;SavedProfile&quot;;<br><br>    private int _currentProfileID;<br>    private string _currentProfileName;<br><br>    private float _fastestTime, _profileFastestTime;<br>    private int _highScore, _profileHighScore;<br>    private string _highScoreName, _fastestTimeName;<br>    [SerializeField] private TMP_Text _highScoreText, _fastestTimeText, _profileHighScoreText, _profileFastestTimeText;<br><br>    private WaitForSeconds _mismatchDelaySeconds = new WaitForSeconds(2f); //the tile delay for a mismatch is hard coded here.<br><br>    #endregion<br>}</pre><p>The <em>Match Manager</em> is listening to the <em>On Tile Select</em> event coming from the <em>tile </em>buttons. When the <em>first tile</em> button is pressed, it passes it’s data to the <em>Match Manager</em>, which stores it for later. When the <em>second tile</em> is pressed, it’s data is also stored and then the <em>Check Match</em> function is called.</p><p>The <em>Check Match</em> function does exactly that, and compares the <em>ID’s</em> of the two selected tiles. The selected tiles are then contacted to let them know if they are matched or not. If there is a <em>match</em>, points are awarded to the player in addition to a time based multiplier. <em>High Scores</em> are checked and saved each match, and the match data is reset.</p><p>If there is a mismatch, no points are awarded, which is sad for the player.</p><p>At least, a <em>coroutine </em>runs so they have a couple of seconds to see their mistake, and remember the mismatched tiles for next time.</p><p>I thought about running a dedicated <em>timer </em>in a coroutine, but instead chose to use <em>Time.time</em> and a couple of <em>float </em>variables to store and calculate <em>match</em>, <em>round </em>and <em>total game</em> times.</p><pre><br>    #region Event Listener On Tile Select<br><br>    private void Tile_onTileSelect(int id, Tile selectedTile)<br>    {<br>        if (_isProcessing) return; //coroutine is checking for match. buttons all should be disabled...<br><br>        //check if first or second selected tile<br>        if (!_firstSelected)<br>        {<br>            //store first tile data<br>            _firstTile = selectedTile;<br>            _a = id;<br>            _firstSelected = true;<br>        }<br>        else<br>        {<br>            if (selectedTile == _firstTile) return; //kick out if selected tile is the same as the first<br><br>            _secondTile = selectedTile; //store second tile data and compare<br>            _b = id;<br><br>            CheckMatch();<br>        }<br>    }<br><br>    #endregion<br><br>    #region Check Match<br><br>    private void CheckMatch()<br>    {<br>        if (_a == _b) //check if both tiles match<br>        {<br>            _matchesFound++; //increment match count<br><br>            _firstTile.OnMatchCheck(true); //let both tiles know they have been matched<br>            _secondTile.OnMatchCheck(true);<br><br>            int totalPairsInRound = _rounds[_round - 1].TileCount / 2; //calculate total pairs in round for points multiplication<br><br>            _elapsedTime = Time.time - _startTime; //calculate elapsed time for match<br>            _startTime = Time.time; //reset start time<br><br>            _timeMultiplier -= (int)_elapsedTime; //reduce time multiplier based on elapsed time<br><br>            if (_timeMultiplier &lt; 1) //have 1 be the lowest multiplier so no point loss<br>                _timeMultiplier = 1;<br><br>            _score += (50 * totalPairsInRound) * _timeMultiplier; //add multiplied points<br>            _scoreText.text = &quot;Score: &quot; + _score.ToString(&quot;N0&quot;, CultureInfo.InvariantCulture); //update score UI<br><br>            HighScore();<br><br>            _timeMultiplier = 10; //reset time multiplier for next match<br><br>            ResetMatchValues();<br><br>            if (_matchesFound &gt;= totalPairsInRound) //check if all matches in the round are complete<br>            {<br>                _roundTime = Time.time - _roundStartTime; //calculate time for round<br>                _roundTimeMultiplier -= (int)_roundTime; //reduce multiplier for time spent<br><br>                if (_roundTimeMultiplier &lt; 1)<br>                {<br>                    _roundTimeMultiplier = 1;<br>                }<br><br>                if (_round == 5) //check if final round Game Win!!!<br>                {<br>                    _gameCompletePanel.SetActive(true);<br><br>                    if (_roundCompleteTimes != null)<br>                        _roundCompleteTimes.Add(_roundTime);<br><br>                    GameCompleteTime(); //calculate time to complete all rounds<br><br>                    FastestGameTime(); //compare game time to fastest profile and overall times<br><br>                    _gameTimeText.gameObject.SetActive(true); //display the current time to beat the game<br><br>                    var time = TimeSpan.FromSeconds(_gameCompleteTime);<br>                    _gameTimeText.text = &quot;Game Complete &quot; + string.Format(&quot;{0:00}:{1:00}&quot;, time.Minutes, time.Seconds);<br><br>                    _score += (500 * totalPairsInRound) * _roundTimeMultiplier; //final score <br>                    _scoreText.text = &quot;Score: &quot; + _score.ToString(&quot;N0&quot;, CultureInfo.InvariantCulture);<br><br>                    HighScore();<br>                }<br>                else<br>                {<br>                    _nextRoundPanel.SetActive(true);<br><br>                    //add round time to the List of round times<br>                    if (_roundCompleteTimes != null)<br>                        _roundCompleteTimes.Add(_roundTime);<br><br>                    //display time to complete round<br>                    var time = TimeSpan.FromSeconds(_roundTime);<br>                    _roundTimeText.text = &quot;Round Complete &quot; + string.Format(&quot;{0:00}:{1:00}&quot;, time.Minutes, time.Seconds);<br><br>                    _score += (100 * totalPairsInRound) * _roundTimeMultiplier; //round score<br>                    _scoreText.text = &quot;Score: &quot; + _score.ToString(&quot;N0&quot;, CultureInfo.InvariantCulture);<br><br>                    HighScore();<br>                }<br>            }<br>        }<br>        else //not a match<br>        {<br>            onLockTiles?.Invoke(); //tiles will disable their click for time so player can see the mismatched tiles. <br><br>            StartCoroutine(MismatchRoutine());<br>        }<br>    }<br><br>    private void ResetMatchValues()<br>    {<br>        _firstSelected = false;<br>        _firstTile = null;<br>        _secondTile = null;<br>        _isProcessing = false;<br>    }<br><br>    #endregion<br>  </pre><p>The <em>Start New Round</em> function gets called from either the <em>start game</em> button, or the subsequent <em>next round</em> button. There isn’t currently a pause behavior in this game, so the player is free to rest as long as needed between rounds without it hurting their overall completion time.</p><p>The <em>Grid Layout Group</em> gets it’s <em>constraint count</em> from the <em>Round Config</em> values. The <em>On Round Start</em> event will destroy any tiles from previous rounds. The needed pairs of tiles are calculated though the config data as well, and then pairs of tiles are added to the <em>paired list</em>. The <em>shuffled list</em> uses <em>Linq </em>to <em>randomize </em>the <em>paired list</em> before the tiles get instantiated as children of the layout group. Each newly born tile button has it’s <em>tile data</em> passed in as soon as it comes into the scene, ready to be clicked.</p><pre>#region Start New Round<br><br>    public void StartNewRound()<br>    {<br>        if (_round &gt;= _rounds.Count) //check if the current round is valid<br>        {<br>            Debug.LogWarning(&quot;The rounds have exceeded the max count!!!&quot;);<br>            return;<br>        }<br><br>        RoundConfig config = _rounds[_round]; //set the round configration for tile count and grid layout<br><br>        _layoutGroup.constraintCount = config.GridConstraint; //set layout group to contsraint count config for round<br><br>        //Reset match data<br>        ResetMatchValues();<br><br>        _matchesFound = 0; //reset total matches for round<br><br>        onRoundStart?.Invoke(); //destroy previous or existing tiles<br><br>        _pairedList.Clear(); //clear paired list for new round<br><br>        int pairsNeeded = config.TileCount / 2; //use config to calculate pairs for round<br><br>        for (int i = 0; i &lt; pairsNeeded; i++) //add all tile matches to the paired list<br>        {<br>            _pairedList.Add(_tileDataList[i]); //first copy<br>            _pairedList.Add(_tileDataList[i]); //second copy<br>        }<br><br>        _shuffledList = _pairedList.OrderBy(x =&gt; UnityEngine.Random.value).ToList(); //shuffle the paired list<br><br>        foreach (TileData data in _shuffledList) //instantiate and set the data on tiles for the round<br>        {<br>            Tile tile = Instantiate(_tilePrefab, _layoutGroup.transform).GetComponent&lt;Tile&gt;();<br><br>            tile.SetData(data);<br>        }<br><br>        _round++;<br>        //update current round UI<br><br>        _startTime = Time.time; //reset the match start time<br>        _roundStartTime = Time.time; //reset the start time for the round<br>        _timeMultiplier = 10; //reset time multipliers<br>        _roundTimeMultiplier = 60;<br>    }<br><br>    #endregion</pre><p>When a <em>match</em> is made, the <em>current score</em> is checked against a high score for the loaded profile, as well as a top high score between all profiles. If high scores are achieved, <em>points </em>and associated <em>names </em>are saved to <em>Player Prefs</em>.</p><p>There is another method for checking fastest times overall and per profile, which works similarly to the high score check using <em>Player Prefs</em>.</p><pre>#region High Score<br><br>    private void HighScore()<br>    {<br>        //check high score vs current score first<br>        if (_score &gt; _highScore)<br>        {<br>            _highScore = _score;<br><br>            PlayerPrefs.SetInt(_highScoreKey, _highScore);<br><br>            if (PlayerPrefs.HasKey(_savedProfile))<br>            {<br>                _highScoreName = _currentProfileName;<br><br>                PlayerPrefs.SetString(_highScoreNameKey, _highScoreName);<br><br>                _highScoreText.text = &quot;Top High Score &quot; + _highScoreName + &quot; &quot; + _highScore.ToString(&quot;N0&quot;, CultureInfo.InvariantCulture);<br>            }<br>            else<br>                _highScoreText.text = &quot;Top High Score &quot; + _highScore.ToString(&quot;N0&quot;, CultureInfo.InvariantCulture);<br>        }<br><br>        if (_score &gt; _profileHighScore)<br>        {<br>            _profileHighScore = _score;<br><br>            if (PlayerPrefs.HasKey(_savedProfile))<br>            {<br>                string profileHighScoreKey = $&quot;Profile_{_currentProfileID}_HighScoreMatch&quot;;<br><br>                PlayerPrefs.SetInt(profileHighScoreKey, _profileHighScore);<br><br>                _profileHighScoreText.text = _currentProfileName + &quot; High Score &quot; + _profileHighScore.ToString(&quot;N0&quot;, CultureInfo.InvariantCulture);<br>            }<br>            else<br>                _profileHighScoreText.text = &quot;High Score &quot; + _profileHighScore.ToString(&quot;N0&quot;, CultureInfo.InvariantCulture);<br>        }<br><br>        PlayerPrefs.Save();<br>    }<br><br>    #endregion</pre><p><strong>Game View</strong></p><p>Please forgive my less than appealing visuals, as I consciously tried to spend minimal time on design. I will leave the design until last, and then write an article on the design process.</p><p>Here is round 1, which consists of 6 tiles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*fMzo-c92GfQF0ejB1F2tvQ.gif" /></figure><p>Let’s pump up round 2 to have 8 tiles. No need to go crazy as this game is designed for younger audiences.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*UaCqesCQZlMrZ-mSuol7og.gif" /></figure><p>Round 3 is a ten tile horizontal spread.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*zsvsI-IxWZMvjiMPh1aUHw.png" /></figure><p>Round 4 offers the user a dozen tiles with 6 matches.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*nh2-3vrS1UO09s2VPuoXcA.png" /></figure><p>Finally, round 5 hosts 16 tiles, showcasing all of the 8 images I have currently in the game. It looks like I have room to grow this on the screen, so maybe I can make another 8 match imges and add a few more levels.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*jnkllOtDQFu5ceR3tRyItg.png" /></figure><p>Here are the final stats for the game, hideous though the layout may be.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*sezyY0xleuPpJPSOt5rkcA.png" /></figure><p>Thanks for joining me in this overview into creating a match 2 game. I hope you join me next time where I cover the second game, a math battle adventure.</p><p>Happy coding and thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=020bc89d6841" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Prototyping a Trio of Mini-Games I: Main Menu]]></title>
            <link>https://jaredamlin.medium.com/prototyping-a-trio-of-mini-games-i-main-menu-60d390bc3f94?source=rss-e55fb2acfa59------2</link>
            <guid isPermaLink="false">https://medium.com/p/60d390bc3f94</guid>
            <category><![CDATA[user-interface]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[prototyping]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <dc:creator><![CDATA[Jared Amlin]]></dc:creator>
            <pubDate>Sun, 29 Mar 2026 00:36:51 GMT</pubDate>
            <atom:updated>2026-04-13T18:14:33.206Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kYFV9s0pqt-tCuIsEgqM0A.png" /></figure><p>Good day reader! Thanks for joining me here. After finishing some modules on UI based game interactions, I will be making a small project that consists of three educational mini-games. If I lured you in with that sweet low-poly cover image, your patience will be greatly rewarded in my later articles where I beautify this ugly prototype. As a visual person, I have a tendency of working on visual elements before the logic is done, so i tried my best to stick to the logic first and foremost!</p><p><strong>Main Menu</strong></p><p>See? I did a great job at not working on anything visual!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dp18ST6xPn0qtuenWjEGYw.png" /></figure><p>Here is the <em>Canvas </em>setup in the <em>Hierarchy</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/273/1*gBMIUXEY4rezMiAuZNpWHw.png" /></figure><p>These buttons use the <em>On Click</em> events to handle UI Panel visibility.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/1*R0qXIelz_cVDwqbEIJIT2w.png" /></figure><p><strong>Settings: <em>Audio</em></strong></p><p>The <em>Settings</em> panel holds adjustments for <em>Music, Sounds, Contrast</em> and <em>Brightness</em>. All settings save to, and load from, <em>Player Prefs</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*hflHRwcEN_ISE2VubNSKhg.png" /></figure><p>The <em>Music Slider</em> has <em>Max </em>and <em>Min </em>values that work with the <em>Audio Managers</em> needs. It also uses a <em>Slider Events</em> script to save using a <em>Serialized Key</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*cV57StWw9CW67BDVqEiUgg.png" /></figure><p>The <em>Sounds Slider</em> works in the same way, only calling a different function on the <em>Audio Manager</em> and using it’s own key for saving.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*oJhl8B6RQRLEGl49oDs_kw.png" /></figure><p>The <em>Slider Events</em> uses the <em>IPointerUpHandler</em> event via Unity’s event systems to save data.</p><pre>using UnityEngine;<br>using UnityEngine.UI;<br>using UnityEngine.EventSystems;<br><br>public class SliderEvents : MonoBehaviour, IPointerUpHandler<br>{<br>    [SerializeField] private string _key;<br>    private Slider _slider;<br><br>    private void Start()<br>    {<br>        _slider = GetComponent&lt;Slider&gt;();<br><br>        if (_slider != null)<br>            _slider.value = PlayerPrefs.GetFloat(_key);<br>    }<br><br>    public void OnPointerUp(PointerEventData eventData)<br>    {<br>        PlayerPrefs.SetFloat(_key, _slider.value);<br>    }<br>}</pre><p>I have yet to add audio other than a soundtrack, so this functionality will grow. For now, the <em>Audio Manager</em> handles adjusting <em>Soundtrack </em>and <em>SFX </em>volumes based on the sliders, as well as loading in any saved settings on start.</p><pre>using UnityEngine;<br>using UnityEngine.Audio;<br><br>public class AudioManager : MonoBehaviour<br>{<br>    [SerializeField] private AudioMixer _audioMixer;<br>    private const string _soundTrack = &quot;Soundtrack&quot;, _sfx = &quot;SFX&quot;;<br><br>    private void Start()<br>    {<br>        Init();<br>    }<br><br>    private void Init()<br>    {<br>        //load saved data from Player Prefs<br>        AdjustSoundtrackVolume(PlayerPrefs.GetFloat(_soundTrack));<br>        AdjustSFXVolume(PlayerPrefs.GetFloat(_sfx));<br>    }<br><br>    public void AdjustSoundtrackVolume(float volume)<br>    {<br>        if (_audioMixer != null)<br>            _audioMixer.SetFloat(_soundTrack, volume);<br>    }<br><br>    public void AdjustSFXVolume(float volume)<br>    {<br>        if (_audioMixer != null)<br>            _audioMixer.SetFloat(_sfx, volume);<br>    }<br>}</pre><p>For this to work, the <em>Parameters </em>must be exposed on the <em>Audio Mixer</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*XVHvaHqw0mk0L-2fyYqzsw.png" /></figure><p><strong>Settings: <em>Post Processing</em></strong></p><p>The <em>Brightness </em>and <em>Contrast </em>sliders work similarly, only using the <em>On Value Changed</em> event to contact the <em>Post Process Manager</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*zXhWlq_i3LRyvJyICtJD3w.png" /></figure><p>Both of these sliders also use the <em>Slider Events</em> script mentioned previously.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1013/1*ZazCfMGrpVjynmmCN1Jhqw.png" /></figure><p>The <em>Post Process Manager</em> is using the <em>Global Volume</em> in the scene.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sc7o0kIl0NzNh0pquDXwhg.png" /></figure><p>The <em>Post Process Manager</em> uses the <em>UnityEngine.Rendering.Universal</em> namespace so I can access the <em>Color Adjustments</em>, which holds the <em>Brightness </em>and <em>Contrast</em>. You want to adjust the running <em>instance </em>of the color adjustments, so both contast and brightness have their <em>override state</em> set to <em>true </em>when this initializes.</p><pre>using UnityEngine;<br>using UnityEngine.Rendering;<br>using UnityEngine.Rendering.Universal;<br><br>public class PostProcessManager : MonoBehaviour<br>{<br>    [SerializeField] private Volume _postProcessVolume;<br>    private ColorAdjustments _colorAdjustments;<br>    private const string _contrast = &quot;Contrast&quot;, _brightness = &quot;Brightness&quot;;<br><br>    private void Awake()<br>    {<br>        Init();<br>    }<br><br>    private void Init()<br>    {<br>        if (_postProcessVolume.profile.TryGet(out _colorAdjustments))<br>        {<br>            //set override state on color adjustments and post exposure instance for user interaction<br>            _colorAdjustments.contrast.overrideState = true;<br>            _colorAdjustments.postExposure.overrideState = true;<br><br>            //load data from Player Prefs<br>            _colorAdjustments.contrast.value = PlayerPrefs.GetFloat(_contrast);<br>            _colorAdjustments.postExposure.value = PlayerPrefs.GetFloat(_brightness);<br>        }<br>        else<br>            Debug.LogWarning(&quot;You Probably need to assign the Post Process Volume in the Inspector.&quot;);<br>    }<br><br>    public void Contrast(float value)<br>    {<br>        if (_colorAdjustments != null)<br>            _colorAdjustments.contrast.value = value;<br>    }<br><br>    public void Brightness(float value)<br>    {<br>        if (_colorAdjustments != null)<br>            _colorAdjustments.postExposure.value = value;<br>    }<br>}</pre><p><strong>Profile Panel</strong></p><p>The player should never see the <em>Profile Panel</em> looking this way, unless everything has gone terribly wrong.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hJMLKpyxR9p9YhfftugU8A.png" /></figure><p>The <em>Scrollbar </em>lets the user navigate through the existing profile <em>Buttons</em>, using <em>Masking </em>and a <em>Horizontal Layout Group</em>. If no existing profiles are found, the only visible button will be the <em>New Profile Button</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/539/1*Z1GL8skGLxzLcZfSKWTUnA.png" /></figure><p>Each <em>Profile Button</em> uses a <em>Profile Display</em> script, and the <em>On Click</em> event to send it’s <em>Profile ID</em> to the <em>Profile Manager</em>. This system currently works on a maximum of eight saved profiles, but it would be easy enough to change that value. The only pre-assigned component here is the <em>Text </em>that will be used to display the profile name.</p><p>When the button is clicked, the ID is used to load the data for that profile. More on that when I get to the <em>Profile Manager</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*MY0ehu0UFK-lLnwZ4heHgA.png" /></figure><p>The each <em>Profile Display</em> is set by the <em>Profile Manager</em> when it loads existing profiles. The <em>Background Image</em> is used to highlight the <em>active </em>profile button.</p><pre>using UnityEngine;<br>using UnityEngine.UI;<br>using TMPro;<br><br>public class ProfileDisplay : MonoBehaviour<br>{<br>    [SerializeField] private TMP_Text _nameText;<br>    [SerializeField] private Image _avatarImage;<br>    [SerializeField] private Image _backgroundImage;<br>    [SerializeField] private int _id;<br><br>    private int _currentAvatarID;<br><br>    public void SetProfile(string playerName, Sprite avatarSprite, int avatarID)<br>    {<br>        _nameText.text = playerName;<br>        _avatarImage.sprite = avatarSprite;<br>        _currentAvatarID = avatarID;<br>    }<br><br>    public void SetSelected(bool isSelected)<br>    {<br>        if (_backgroundImage == null)<br>            _backgroundImage = GetComponent&lt;Image&gt;();<br><br>        if (_backgroundImage != null)<br>        {<br>            _backgroundImage.color = isSelected ? Color.yellow : Color.white;<br>        }<br>    }<br>}</pre><p>Each <em>Profile Button </em>also has a child <em>Edit </em>button. Pressing the <em>Profile Button</em> will set that profile as the active one, while the <em>edit</em> button will bring up the <em>Edit Profile Panel, </em>also tracking which profile is the active one via an ID.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/915/1*Tf1lyY-97dzD-yaTMQqXtw.png" /></figure><p>The <em>Edit Profile Panel</em> will display the current profile <em>name</em>, <em>avatar </em>and some <em>high scores</em> for the mini-games. There is a button to <em>delete </em>the profile, which brings up a warning screen that will actually delete the profile when the following button is pressed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*3dkocZYfyeqyc1dP3Xlt0A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*L1mXSqTf-gEdaASSTe26Ow.png" /></figure><p>Pressing the <em>Edit </em>button near the player name will bring up an <em>Input Field</em> for the user to rename the profile.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*aTO-t9scYLGlbGxivYrgwA.png" /></figure><p>Pressing the <em>Edit</em> button on the <em>Avatar </em>will bring up the <em>Avatar Select Panel</em>. When you press an <em>Avatar </em>button, this menu will hide and assign the selected sprite to the avatar <em>Image</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*6b6uwaknoaAk9dk6zbsSyA.png" /></figure><p>Pressing the <em>Back Button</em> on the <em>Edit Profile Panel</em> will <strong><em>save </em></strong>the profiles name and avatar to <em>Player Prefs</em>, hide the edit panel, and then activate a <em>Profile Display </em>with the new data on the <em>Profile Panel</em>.</p><p>Each <em>Avatar </em>button stores a reference to it’s <em>ID, name</em> and <em>Sprite</em>. It also has public returns for those data points. I’ll have to take another look at my <em>Profile Manager</em> and see if it makes sense to return all of those at once.</p><pre>using UnityEngine;<br><br>public class Avatar : MonoBehaviour<br>{<br>    [SerializeField] private string _name;<br>    [SerializeField] private int _ID;<br>    [SerializeField] private Sprite _sprite;<br><br>    public string GetAvatarName()<br>    {<br>        return _name;<br>    }<br><br>    public int GetAvatarID()<br>    {<br>        return _ID;<br>    }<br><br>    public Sprite GetAvatarSprite()<br>    {<br>        return _sprite;<br>    }<br>}</pre><p>The <em>On Click Event</em> on the <em>Avatar </em>button sends the ID number to the <em>Profile Manager</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*48R1Um1i_37EIld86EJjlA.png" /></figure><p>If you have less than the maximum amount of profiles stored when you run the game, the <em>New Profile Button</em> will appear at the far right on the <em>Profile Panel</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*qCP-Isv3QOA4pgHV3R6xvA.png" /></figure><p>The <em>New Profile Button</em> let’s the <em>Profile Manager</em> know it needs to do it’s thing, and then opens up the <em>Edit Profile Panel</em>, which will eventually <em>save </em>upon closing and populate a new <em>Profile Display</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*Eo1FxpqMKXbnTi303_-DGA.png" /></figure><p>The <em>Profile Panel</em> also has a <em>button </em>to <em>Clear All</em> saved data, which of course brings up this warning panel before you commit to wiping <em>Player Prefs</em> clean.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*YHK3wZOfe7X-Cqg5_ZChmA.png" /></figure><p><strong>Profile Manager</strong></p><p>I’ll admit…this script became bloated and I even got help from Ai at some point to help refactor parts of my own working solution, with some heavy guidance from my end. I won’t burden you, the innocent reader, with the entirety of this script. So I will instead break it down into various functions and other bits.</p><p>Essentially, the <em>Profile Manager</em> keeps references to an <em>Array </em>of <em>Profile Displays </em>for showcasing avatars and names for each existing profile. The <em>New Profile Button</em> game object is stored, as well as the <em>Input Field</em>, player name <em>Text </em>and avatar <em>Image</em>. The <em>List </em>of avatar <em>Sprites </em>is used with a <em>Dictionary </em>to store avatar ID’s in <em>Player Prefs</em>, so I can load them back in when the game runs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*egBb47tKXYl2-wfH1alfMA.png" /></figure><p><strong>Variables</strong></p><p>By tracking the current <em>profile </em>and <em>avatar </em>ID, I can make sure I am saving over the correct slot in <em>Player Prefs</em>.</p><pre>#region Variables<br><br>    //Maximum Profiles that can be saved to disk<br>    private const int MaxProfiles = 8;<br><br>    //Profile Displays for max profiles<br>    [SerializeField] private ProfileDisplay[] _profileDisplays;<br><br>    //Profile UI and loading data<br>    [SerializeField] private TMP_InputField _profileNameInputField;<br>    [SerializeField] private TMP_Text _nameText;<br>    [SerializeField] private Image _avatarImage;<br>    private int _currentProfileID;<br>    private int _currentAvatarID;<br>    private int _profileCount; //used to check current profiles<br>    <br>    //Profile Data<br>    private string _playerName;<br>    private int _avatarID;<br>    private Sprite _avatarSprite;<br>    private const string _savedProfile = &quot;Saved Profile&quot;;<br><br>    //New Profile Button<br>    [SerializeField] private GameObject _newProfileButton;<br><br>    //Avatar Sprites for Profiles<br>    [SerializeField] private List&lt;Sprite&gt; _avatarSpritesList; //All Avatar Sprites in Game<br>    private Dictionary&lt;int, Sprite&gt; _avatarDictionary; //Use Dictionary to get sprite from ID<br><br>    //Game stats for Profiles<br>    [SerializeField] private TMP_Text _mathBattleHighScoreText; //Math Battle High Score between all Profiles<br><br>    #endregion</pre><p><strong>Initialization</strong></p><p>The avatar <em>dictionary </em>is <em>initialized </em>with the each <em>sprite </em>in the <em>array </em>before calling the big <em>Load All Profiles </em>function<em>.</em></p><pre>private void Start()<br>{<br>    Init();<br>}<br> <br>private void Init()<br>{<br>    //Initialize avatar dictionary from list<br>    _avatarDictionary = new Dictionary&lt;int, Sprite&gt;();<br><br>    if (_avatarSpritesList != null)<br>    {<br>        //Assign Sprites to Dictionary from Sprite List<br>        for (int i = 0; i &lt; _avatarSpritesList.Count; i++)<br>        {<br>            _avatarDictionary[i] = _avatarSpritesList[i];<br>        }<br>    }<br>    else<br>       Debug.LogWarning(&quot;You Probably need to assign some Avatar Sprites in the Inspector.&quot;);<br><br>    //Load saved from PlayerPrefs and Initialize UI<br>    LoadAllProfiles();<br>}</pre><p>Profile <em>names </em>and <em>avatars </em>are saved to <em>Player Prefs</em> using a local <em>string </em>value with an appended <em>index</em>. A for loop checks for existing names in <em>Player Prefs </em>per available profile ID. If a profile is found, I store the <em>name </em>of the profile and then check for an existing avatar <em>key</em>. If an avatar key is found, it is checked against the <em>dictionary </em>before attempting to grab the corresponding <em>sprite</em>. Each found profile will have it’s <em>Profile Display</em> object activated, and then pass in the needed <em>name</em>, <em>avatar </em>and <em>id</em> via the <em>Set Profile</em> parameters.</p><p>If no profile is found for that save slot, the <em>Profile Display</em> will hide.</p><p>If the <em>profile count </em>shows that all available slots are occupied after loading, the <em>new profile button</em> will hide away.</p><p>I store the <em>current profile ID</em> so that the most recently played profile will be active and <em>highlighted </em>on the <em>profile display</em> when the game loads.</p><pre>    //Load all profiles from PlayerPrefs<br>    private void LoadAllProfiles()<br>    {<br>        //Default to Zero as this will increment to check for existing profiles<br>        _profileCount = 0;<br><br>        //Check Player Prefs for existing profile using appended name and ID<br>        for (int i = 0; i &lt; MaxProfiles; i++)<br>        {<br>            string nameKey = $&quot;Profile_{i}_Name&quot;;<br>            string avatarKey = $&quot;Profile_{i}_AvatarID&quot;;<br><br>            //check if the name and avatar keys exist for saved profile data<br>            if (PlayerPrefs.HasKey(nameKey))<br>            {<br>                _profileCount++;<br><br>                //store data for existing Profile Name and Avatar. Add in High Score and Best times for games here. <br>                _playerName = PlayerPrefs.GetString(nameKey);<br><br>                //check for saved avatar or assign default<br>                if (PlayerPrefs.HasKey(avatarKey))<br>                {<br>                    _avatarID = PlayerPrefs.GetInt(avatarKey);<br><br>                    //Check if avatarID exists in dictionary or set to default if not<br>                    _avatarSprite = _avatarDictionary.ContainsKey(_avatarID) ? _avatarDictionary[_avatarID] : null;<br>                }<br><br>                if (_profileDisplays != null)<br>                {<br>                    //Activate profile displays and set data per saved profile<br>                    _profileDisplays[i].gameObject.SetActive(true);<br>                    _profileDisplays[i].SetProfile(_playerName, _avatarSprite, _avatarID);<br>                }<br>                else<br>                    Debug.LogWarning(&quot;You Probably need to assign the Profile Displays in the Inspector.&quot;);<br>            }<br>            else<br>            {<br>                //No saved profile, deactivate display for this save ID<br>                _profileDisplays[i].gameObject.SetActive(false);<br>            }<br>        }<br><br>        //Deactivate New Profile Button if the Maximum amount of profiles has been reached <br>        if (_profileCount &gt;= MaxProfiles)<br>        {<br>            _newProfileButton.gameObject.SetActive(false);<br>        }<br><br>        //Check Player Prefs for most recently used profile<br>        if (_profileCount &gt; 0 &amp;&amp; PlayerPrefs.HasKey(_savedProfile))<br>        {<br>            _currentProfileID = PlayerPrefs.GetInt(_savedProfile);<br>            <br>            HighlightActiveProfile();<br>        }<br>        else<br>        {<br>            //assign first available profile as active<br>            AssignActiveProfile();<br>        }<br>    }</pre><p><strong>Saving</strong></p><p>As the comments say, the <em>Save Data</em> function is called from the back button when you close the <em>Edit Profile Panel</em>. I wanted to avoid the player being able to save an empty string name, so it will default to <em>New Player</em> with an appended <em>profile ID</em> if they try. That of course can always be edited later by the user. Otherwise, the <em>Save Profile</em> function is called, and the <em>Parameters </em>are fulfilled using the <em>current profile ID</em>, the entered <em>name </em>text from the <em>Input Field</em>, and the <em>current avatar ID</em> from whatever was chosen by the user on the edit panel.</p><p>After checking that the profile save <em>index </em>is acceptable, the <em>name, avatar</em> and most recently played <em>profile </em>are stored to <em>Player Prefs</em>. The <em>Profile Displays</em> then immediately update to reflect the changes as the <em>edit </em>panel hides and the <em>profile panel</em> appears again. Lastly, the saved profile, <em>new </em>or <em>edited</em>, is set to be <em>active </em>and <em>highlighted </em>visually.</p><pre>#region Save<br><br>    public void SaveData() //called from Back Button on Edit Profile Menu<br>    {<br>        //assign default profile name if the input field was left blank<br>        if (_profileNameInputField.text == &quot;&quot;) <br>        {<br>            _profileNameInputField.text = $&quot;New Player {_currentProfileID}&quot;;<br>        }<br><br>        SaveProfile(_currentProfileID, _profileNameInputField.text, _currentAvatarID);<br>    }<br><br>    //Save a Profile by index, name and avatarID<br>    private void SaveProfile(int profileIndex, string playerName, int avatarID)<br>    {<br>        //check if profile index is within the given range of profiles<br>        if (profileIndex &lt; 0 || profileIndex &gt;= MaxProfiles)<br>        {<br>            Debug.LogWarning($&quot;The Profile Index of {profileIndex} is out of range for saving.&quot;);<br>            return;<br>        }<br><br>        PlayerPrefs.SetString($&quot;Profile_{profileIndex}_Name&quot;, playerName);<br>        PlayerPrefs.SetInt($&quot;Profile_{profileIndex}_AvatarID&quot;, avatarID);<br>        PlayerPrefs.SetInt(_savedProfile, profileIndex);<br>        PlayerPrefs.Save();<br><br>        //Update UI<br>        if (_profileDisplays != null)<br>        {<br>            if (_profileDisplays[profileIndex] != null)<br>            {<br>                _profileDisplays[profileIndex].gameObject.SetActive(true);<br>                _profileDisplays[profileIndex].SetProfile(playerName, _avatarDictionary[avatarID], avatarID);<br>            }<br>        }<br><br>        CheckProfiles();<br><br>        HighlightActiveProfile();<br>    }<br><br>    #endregion</pre><p><strong>Profile Display Visibility</strong></p><p>This function checks for existing profiles, and then <em>activates </em>or <em>hides </em>the corresponding display. The <em>New Profile Button</em> then handles it’s own visibility depending on the <em>maximum </em>profile count.</p><pre>#region Profile Display Visibility<br><br>    private void CheckProfiles() //handle Profile Display visibility if a saved profile is found or not. <br>    {<br>        _profileCount = 0;<br><br>        for (int i = 0; i &lt; MaxProfiles; i++)<br>        {<br>            string nameKey = $&quot;Profile_{i}_Name&quot;;<br><br>            if (PlayerPrefs.HasKey(nameKey))<br>            {<br>                _profileCount++;<br><br>                if (_profileDisplays[i] != null)<br>                    _profileDisplays[i].gameObject.SetActive(true);<br>            }<br>            else<br>            {<br>                if (_profileDisplays[i] != null)<br>                    _profileDisplays[i].gameObject.SetActive(false);<br>            }<br>        }<br><br>        SetNewProfileButton();<br>    }<br><br>    private void SetNewProfileButton() //Enable or Disable the New Profile Button based on Max Profiles<br>    {<br>        if (_newProfileButton != null)<br>        {<br>            _newProfileButton.SetActive(_profileCount &lt; MaxProfiles);<br>        }<br>    }<br><br>    #endregion</pre><p><strong>Delete Profile</strong></p><p>Most people aren’t going to want to delete all of their saved data, so the <em>Delete Profile</em> option is available to remove profile data by <em>index</em>, and then immediately update the <em>profile displays</em>.</p><pre>#region Delete Profile<br><br>    public void RemoveProfile() //called from UI button after checking with user they are certain to delete<br>    {<br>        DeleteProfile(_currentProfileID);<br>    }<br><br>    //Delete a profile by index<br>    private void DeleteProfile(int profileIndex)<br>    {<br>        //check if profile index is within the given range of profiles<br>        if (profileIndex &lt; 0 || profileIndex &gt;= MaxProfiles)<br>        {<br>            Debug.LogWarning($&quot;The Profile Index of {profileIndex} is out of range for deletion.&quot;);<br>            return;<br>        }<br><br>        PlayerPrefs.DeleteKey($&quot;Profile_{profileIndex}_Name&quot;);<br>        PlayerPrefs.DeleteKey($&quot;Profile_{profileIndex}_AvatarID&quot;);<br>        PlayerPrefs.Save();<br><br>        if (_profileDisplays != null)<br>        {<br>            if (_profileDisplays[profileIndex] != null)<br>            {<br>                // Deactivate profile display<br>                _profileDisplays[profileIndex].gameObject.SetActive(false);<br>            }<br>        }<br><br>        CheckProfiles();<br>        <br>        AssignActiveProfile();<br>    }<br><br>    #endregion</pre><p>This article is getting long enough, so I won’t go into the remaining methods this whale of a manager has available. I may try to refactor a lot of the looping through and looking for name keys, into a return type function to be used rather than similar functionality plugged in all over the place.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*y0WgvJ85rcRSOfncR7Tzwg.png" /></figure><p><strong>Load Game</strong></p><p>The <em>Start</em> button on the <em>Main Menu</em> brings up the <em>Load Game Panel</em>. Each game has a <em>button </em>that will load it’s scene based on <em>index</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*_ezrccPlirPnpGVGLBEeSg.png" /></figure><p>Here is an example with the <em>Match Game</em> button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*U41UDhatvEeqAKb0-9xssg.png" /></figure><p>This <em>Game Manager</em> ended up being a scene manager, using async loading by <em>index </em>with some commented out stuff in case things slow down and I want to use a visual slider for loading.</p><pre>using System.Collections;<br>using UnityEngine;<br>using UnityEngine.SceneManagement;<br><br>public class GameManager : MonoBehaviour<br>{<br>    public void LoadScene(int sceneIndex)<br>    {<br>        StartCoroutine(LoadSceneAsync(sceneIndex));<br>    }<br><br>    private IEnumerator LoadSceneAsync(int sceneIndex) //use Slider and add loading text if scene starts to take time loading<br>    {<br>        //_loadSceneSlider.gameObject.SetActive(true);<br><br>        AsyncOperation asyncLoadScene = SceneManager.LoadSceneAsync(sceneIndex);<br><br>        while (!asyncLoadScene.isDone)<br>        {<br>            //_loadSceneSlider.value = asyncLoadScene.progress;<br>            //_loadSceneText.text = (asyncLoadScene.progress * 100) + &quot;%&quot;;<br><br>            yield return null;<br>        }<br>    }<br>}</pre><p>I can’t believe I was going to talk about the mini-games in this article. Absolutely not. I think you have suffered long enough. If you are still here with me though through all of this, <strong>thank you</strong>!</p><p>I hope to see you next time where I start diving into these mini-games!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60d390bc3f94" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[UI Events Interfaces in Unity]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://jaredamlin.medium.com/ui-events-interfaces-in-unity-99c9f436ba91?source=rss-e55fb2acfa59------2"><img src="https://cdn-images-1.medium.com/max/710/1*ngXt2rzDeMxcpSJBjbpUdA.gif" width="710"></a></p><p class="medium-feed-snippet">I have been using Unity Engine for almost five years now, and I never knew about these built in Interfaces for UI Events!</p><p class="medium-feed-link"><a href="https://jaredamlin.medium.com/ui-events-interfaces-in-unity-99c9f436ba91?source=rss-e55fb2acfa59------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://jaredamlin.medium.com/ui-events-interfaces-in-unity-99c9f436ba91?source=rss-e55fb2acfa59------2</link>
            <guid isPermaLink="false">https://medium.com/p/99c9f436ba91</guid>
            <category><![CDATA[made-with-unity]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[user-interface]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[application-development]]></category>
            <dc:creator><![CDATA[Jared Amlin]]></dc:creator>
            <pubDate>Mon, 26 Jan 2026 15:03:21 GMT</pubDate>
            <atom:updated>2026-01-26T15:03:21.947Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Layout Groups with Unity UI]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://jaredamlin.medium.com/layout-groups-with-unity-ui-e586391d6196?source=rss-e55fb2acfa59------2"><img src="https://cdn-images-1.medium.com/max/882/1*9NzSdKqTtB_Xek_Bl2n7CQ.gif" width="882"></a></p><p class="medium-feed-snippet">Using Layout Groups is a fast way to organize many UI elements without having to position them all manually. Let&#x2019;s take a look at the&#x2026;</p><p class="medium-feed-link"><a href="https://jaredamlin.medium.com/layout-groups-with-unity-ui-e586391d6196?source=rss-e55fb2acfa59------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://jaredamlin.medium.com/layout-groups-with-unity-ui-e586391d6196?source=rss-e55fb2acfa59------2</link>
            <guid isPermaLink="false">https://medium.com/p/e586391d6196</guid>
            <category><![CDATA[user-interface]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[made-with-unity]]></category>
            <category><![CDATA[ui]]></category>
            <dc:creator><![CDATA[Jared Amlin]]></dc:creator>
            <pubDate>Thu, 22 Jan 2026 19:32:42 GMT</pubDate>
            <atom:updated>2026-01-22T19:32:42.432Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Making A Simple Pause Settings Menu in Unity]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://jaredamlin.medium.com/making-a-simple-pause-settings-menu-in-unity-56228e4ddd59?source=rss-e55fb2acfa59------2"><img src="https://cdn-images-1.medium.com/max/775/1*cv4w-M5Cp2kWnSn-ddBr0g.gif" width="775"></a></p><p class="medium-feed-snippet">Giving the player the ability to pause the game and adjust settings is very commonplace these days. Let&#x2019;s take a look at setting up a very&#x2026;</p><p class="medium-feed-link"><a href="https://jaredamlin.medium.com/making-a-simple-pause-settings-menu-in-unity-56228e4ddd59?source=rss-e55fb2acfa59------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://jaredamlin.medium.com/making-a-simple-pause-settings-menu-in-unity-56228e4ddd59?source=rss-e55fb2acfa59------2</link>
            <guid isPermaLink="false">https://medium.com/p/56228e4ddd59</guid>
            <category><![CDATA[made-with-unity]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[user-interface]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <dc:creator><![CDATA[Jared Amlin]]></dc:creator>
            <pubDate>Mon, 19 Jan 2026 12:02:38 GMT</pubDate>
            <atom:updated>2026-01-19T12:02:38.779Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[UI Based PIN Pad in Unity]]></title>
            <link>https://jaredamlin.medium.com/ui-based-pin-pad-in-unity-3230e9e7aee4?source=rss-e55fb2acfa59------2</link>
            <guid isPermaLink="false">https://medium.com/p/3230e9e7aee4</guid>
            <category><![CDATA[user-interface]]></category>
            <category><![CDATA[application-development]]></category>
            <category><![CDATA[made-with-unity]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[ui]]></category>
            <dc:creator><![CDATA[Jared Amlin]]></dc:creator>
            <pubDate>Sat, 17 Jan 2026 10:55:38 GMT</pubDate>
            <atom:updated>2026-01-17T10:55:38.759Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*KPKKeCVfI5dMZe-mJL0n7w.gif" /></figure><p>I’m going to keep these UI articles moving and dive a bit deeper, making a PIN pad that’s controlled by UI buttons. Let’s go!</p><p><strong>Setup</strong></p><p>Here is my quick design in the game view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*aUPZGDpkWz_9lpioCHkHTQ.png" /></figure><p>The background images are just default UI <em>images </em>with no sprite attached. I am just adjusting the size, position and color of the <em>image </em>component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*wX2disPrBtf5YIwuoIGMNA.png" /></figure><p>The <em>Results Text</em> here that says PIN, will be used to let the user know when they are typing, and if the PIN is correct.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*mlFGSBHEJFEPhDxlL4_PSQ.png" /></figure><p>The <em>Output Text</em> 1234 will be adjusted when the user presses numeric <em>buttons</em>, and sits on top of a white background image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LBIvMolgDEltCtHiOcZdGQ.png" /></figure><p>A <em>Grid Layout Group</em> is used to make designing the child buttons quick and painless.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9zEMMtfKpgr4q5r2CCHE-g.png" /></figure><p>The <em>Clear </em>button uses the <em>On Click</em> event to ping the <em>Clear PIN</em> method on the <em>Button Manager</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*p79z1xXQMwCgnFLp4UFf7A.png" /></figure><p>The <em>Enter </em>button uses the <em>On Click</em> event to ping the <em>Enter PIN</em> method on the <em>Button Manager</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*WAs_rmPRePKiSxRO4BAzBQ.png" /></figure><p>Each numeric button has a <em>Button Object</em> script attached to it, and uses it’s own<em> On Click</em> event to run the <em>Button Press</em> method on the script instance. The <em>Button ID</em> is assigned in the inspector, and represents the value of the button being pressed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*aZaeOYWhXEfRHHyc617zyg.png" /></figure><p>The <em>Button Manager</em> is attached to the main parent object on the PIN pad design, and holds values for the <em>PIN number, Output</em> and <em>Results Texts</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*LVoJnZitq7OlUQfTx31iAg.png" /></figure><p><strong>Scripting</strong></p><p>This simple <em>Button Object</em> script uses a <em>button ID</em> to let the <em>Button Manager</em> know which button has been pressed. When the button is pressed, the <em>On Button Interact</em> event is raised and the <em>button ID</em> is passed to the <em>Button Manager.</em></p><pre>using System.Collections;<br>using System.Collections.Generic;<br>using UnityEngine;<br>using System;<br><br>public class ButtonObject : MonoBehaviour<br>{<br>    [SerializeField] private int _buttonID;<br><br>    public static event Action&lt;int&gt; OnButtonInteract;<br><br>    public void ButtonPress()<br>    {<br>        OnButtonInteract?.Invoke(_buttonID);<br>    }<br>}</pre><p>The <em>Button Manager</em> has values for the<em> stored PIN</em>, the <em>entered PIN</em>, as well as the <em>Output </em>and<em> Results Texts</em>. When the game runs, the <em>Output Text</em> is cleared using the <em>Clear PIN</em> method. The <em>Results Text</em> prompts the user to enter their PIN, and then the <em>Button Manager </em>subscribes to the <em>On Button Interact</em> event.</p><p>Because this is a PIN and should be 4 digits, if a button is pressed and the <em>Output Text</em> is already 4 digits, nothing further will happen. Otherwise, the <em>button ID</em> is converted to a <em>string </em>and added to the <em>Output Text</em>.</p><p>Once the PIN is entered, the <em>Output Text</em> is parsed and compared to the stored PIN value.</p><pre>using UnityEngine;<br>using TMPro;<br><br>public class ButtonManager : MonoBehaviour<br>{<br>    [SerializeField] private int _PIN;<br>    [SerializeField] private int _enteredPin;<br>    [SerializeField] private TMP_Text _outputText;<br>    [SerializeField] private TMP_Text _resultsText;<br><br>    // Start is called before the first frame update<br>    void Start()<br>    {<br>        ClearPIN();<br><br>        _resultsText.text = &quot;Enter PIN&quot;;<br><br>        ButtonObject.OnButtonInteract += ButtonObject_OnButtonInteract;<br>    }<br><br>    private void OnDisable()<br>    {<br>        ButtonObject.OnButtonInteract -= ButtonObject_OnButtonInteract;<br>    }<br><br>    private void ButtonObject_OnButtonInteract(int buttonID)<br>    {<br>        if (_outputText.text.Length &lt; 4)<br>        {<br>            _resultsText.text = &quot;Typing...&quot;;<br>            _outputText.text += buttonID.ToString();<br>        }<br>    }<br><br>    public void EnterPIN()<br>    {<br>        if (_PIN == int.Parse(_outputText.text))<br>        {<br>            Debug.Log(&quot;Correct PIN.&quot;);<br>            _resultsText.text = &quot;Correct PIN Entered.&quot;;<br>            ClearPIN();<br>        }<br>        else<br>        {<br>            Debug.Log(&quot;Incorrect PIN.&quot;);<br>            _resultsText.text = &quot;Incorrect PIN. Try Again.&quot;;<br>            ClearPIN();<br>        }<br>    }<br><br>    public void ClearPIN()<br>    {<br>        _outputText.text = &quot;&quot;;<br>    }<br>}</pre><p><strong>Results</strong></p><p>Here I try to press more than 4 digits, as well as entering the wrong PIN.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*x4HLtwS3295NljSx9hIFKA.gif" /></figure><p>The clear button is working great!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*xtmlf9u39cG2s0nhavzm0Q.gif" /></figure><p>No more secure of a PIN number than 1234!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*KPKKeCVfI5dMZe-mJL0n7w.gif" /></figure><p>I hope you enjoyed this article on making a UI based PIN pad in Unity, and thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3230e9e7aee4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Drop Down Menus in Unity]]></title>
            <link>https://jaredamlin.medium.com/drop-down-menus-in-unity-1c5858e87c22?source=rss-e55fb2acfa59------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c5858e87c22</guid>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[made-with-unity]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[user-interface]]></category>
            <category><![CDATA[unity3d]]></category>
            <dc:creator><![CDATA[Jared Amlin]]></dc:creator>
            <pubDate>Fri, 16 Jan 2026 10:57:09 GMT</pubDate>
            <atom:updated>2026-01-16T10:57:09.847Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*TREzldNnVBgSF6Fgfly4Hw.gif" /></figure><p>When you need a lot of options for the player to choose from, nicely packed into the size of a button, Unity has you covered with <em>drop down</em> menus. Let’s take a look at setting one up and using it.</p><p>After creating a drop down in the <em>Hierarchy</em>, you can see a host of children objects, many of which are disabled. These will enable as needed with behind the scenes mechanics of the drop down. If there are way too many items to fit in the menu, the <em>Scrollbar </em>will automatically activate to save visual space.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*FRWwnLFbEvgJpj5fdCfY_g.png" /></figure><p>Here is what the default <em>drop down</em> menu looks like after creation. I want to replace my <em>difficulty </em>toggle with this drop down instead.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oHZKa1-NNESGG_toZIi1Ww.png" /></figure><p>I’ll do some color adjustment and positioning to match the rest of the UI design.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/1*MgMsCuIkmhbN-I6YDOq3rw.png" /></figure><p>The <em>Options </em>area is where you can add as many different options for your drop down as needed. There is also an <em>On Value Changed</em> event which passes an <em>int </em>parameter to use for which option was selected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*cCELEY0-jx4qhFpjUL6a1w.png" /></figure><p>The <em>Label </em>object says <em>Option A</em> in the <em>Text </em>field, but any changes here will be overwritten by what you type into the <em>Options </em>array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O4UZWv9PDLW6vK352KLmxw.png" /></figure><p>This is a screen shot with the defaults before changing the names of my <em>options </em>to reflect the difficulty level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*oTTMfh1VayJS6_3H3c9MCw.png" /></figure><p>The <em>drop down</em> works as expected in play mode, so now just to hook it up to the <em>Main Menu</em> script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*TREzldNnVBgSF6Fgfly4Hw.gif" /></figure><p>I can use the same public method that the toggle was previously using.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/473/1*BSs5tX79bTcLg7ZQxvs8gA.png" /></figure><p>Here in the <em>Difficulty Toggle</em> function, a <em>switch </em>statement is used to break up the logic for the incoming <em>index</em>, and then send a <em>debug </em>message to the console telling me which one was selected.</p><pre>public void DifficultyToggle(int toggleIndex)<br>    {<br>        switch (toggleIndex)<br>        {<br>            case 0:<br>                Debug.Log(&quot;Easy Difficulty Set&quot;);<br>                break;<br>            case 1:<br>                Debug.Log(&quot;Medium Difficulty Set&quot;);<br>                break;<br>            case 2:<br>                Debug.Log(&quot;Hard Difficulty Set&quot;);<br>                break;<br>            default:<br>                Debug.LogWarning(&quot;There is no case for this difficulty.&quot;);<br>                break;<br>        }<br>    }</pre><p>Here are the debug messages letting me know things are working as intended!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*iVujVrW-R_RXa6eULPdR5A.png" /></figure><p>That’s it for this short article on drop down menus. Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c5858e87c22" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Input Fields in Unity]]></title>
            <link>https://jaredamlin.medium.com/input-fields-in-unity-20cd45dd9c1c?source=rss-e55fb2acfa59------2</link>
            <guid isPermaLink="false">https://medium.com/p/20cd45dd9c1c</guid>
            <category><![CDATA[input-field]]></category>
            <category><![CDATA[user-interface]]></category>
            <category><![CDATA[unity-input-system]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Jared Amlin]]></dc:creator>
            <pubDate>Thu, 15 Jan 2026 11:32:37 GMT</pubDate>
            <atom:updated>2026-01-15T11:32:37.396Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*Y-91RwVcVUIFuxo8yyh2rg.gif" /></figure><p>One of the most powerful features of Unity’s UI system in my opinion, are <em>Input Fields</em>. If you want to make an application or game where the player needs to be able to enter data, the <em>Input Field</em> is your best friend. Let’s take a dive into setting up and using <em>Input Fields</em> in a variety of scenarios!</p><p><strong>Input Fields</strong></p><p>Let’s start simple by letting the <em>Player </em>enter their <em>Name</em>. When you create an <em>Input Field</em>, it comes with child objects by default. The <em>Placeholder </em>object is the light grey <em>‘Enter Text…’</em> area, and the <em>Text </em>object is where the data the player enters is stored.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*dFwZ7Sfs1xCX1hqUeudRhw.png" /></figure><p>I’m using a <em>Text Mesh Pro</em> input field, so I need to use the <em>UnityEngine.UI</em> and <em>TMPro</em> namespaces. I have two variables here, one for the <em>TMP Input Field</em>, and another for my output text. When the player is interacting with the input field, the <em>Typing </em>method will be called. Once the player has finished typing and presses the <em>enter </em>key, the <em>Input Field</em> method will be called. Here the <em>output </em>text is assigned to the value of the <em>text </em>on the <em>input field</em>.</p><pre>using System.Collections;<br>using UnityEngine;<br>using UnityEngine.UI;<br>using TMPro;<br><br>public class MainMenu : MonoBehaviour<br>{<br>    [SerializeField] private TMP_InputField _inputField;<br>    [SerializeField] private TMP_Text _outputText;<br><br>    public void Typing()<br>    {<br>        _outputText.text = &quot;Typing...&quot;;<br>    }<br><br>    public void InputField()<br>    {<br>        _outputText.text = &quot;They shall call you &quot; + _inputField.text;<br>    }<br>}</pre><p>The <em>On Value Changed</em> event on the <em>Input Field</em> will call the <em>Typing </em>method on the <em>Main Menu</em> script. The <em>On End Edit</em> event will ping the <em>Input Field</em> method when the player presses the <em>enter </em>button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*JKDPrEb1MA0RE3bCQ8L7gw.png" /></figure><p>Here are the results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*W_nmE7jPJz4X6Sg-xcG0vw.gif" /></figure><p>The <em>Input Field</em> has many of the same options as other UI elements regarding <em>Interactable, Transitions</em> and <em>Navigation</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*_BJ5uMlRlr7598E5BkPJdQ.png" /></figure><p>The <em>Input Field Settings</em> has the <em>Character Limit</em>, which will be <em>unlimited </em>if set to the default of <em>zero</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*CPZV8JyIgFQa4r_eg3yBEg.png" /></figure><p>The <em>Content Type</em> dropdown features a host of options for a variety of needs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*MC9xhN8tBDAegwscO1p-kQ.gif" /></figure><p>There are four events which can be used such as <em>On Value Change</em>, <em>On Edit String</em>, <em>On Select</em> and <em>On Deselect</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*ecRn59fzXilDsla6xXBfXQ.png" /></figure><p><strong>User Name and Password</strong></p><p>Lets expand on the name input field by storing and checking a <em>user name</em> and <em>password</em>. Both the <em>Name </em>and <em>Password Input Fields</em> are positioned one on top of the other, but will not show at the same time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/322/1*swGMOefPmFBpjDjFF2xwKA.png" /></figure><p>The <em>Input Field Name</em> method is called from the<em> On End Edit</em> event on the <em>Name</em> input field. The <em>value </em>entered into the <em>name input field</em> gets stored in the <em>Player Prefs</em>. Now we have some data that can be checked when someone logs in!</p><p>The <em>Input Password</em> method works similarly, storing the <em>password </em>to <em>Player Prefs.</em> <em>Player Prefs</em> is probably not the safest place to store sensitive data like this, but it will work fine for this article on input fields.</p><pre>using System.Collections;<br>using UnityEngine;<br>using UnityEngine.UI;<br>using TMPro;<br><br>public class MainMenu : MonoBehaviour<br>{<br>    [SerializeField] private TMP_InputField _inputField;<br>    [SerializeField] private TMP_Text _outputText;<br><br>    private void Start()<br>    {<br>        _inputFieldPassword.gameObject.SetActive(false);<br>    }<br><br>    public void Typing()<br>    {<br>        _outputText.text = &quot;Typing...&quot;;<br>    }<br><br>    public void InputFieldName()<br>    {<br>        _outputText.text = &quot;They shall call you &quot; + _inputFieldName.text;<br><br>        PlayerPrefs.SetString(&quot;Name&quot;, _inputFieldName.text);<br>    }<br><br>    public void InputPassword()<br>    {<br>        PlayerPrefs.SetString(&quot;Password&quot;, _inputFieldPassword.text);<br><br>        _outputText.text = &quot;Your username is &quot; + PlayerPrefs.GetString(&quot;Name&quot;) + &quot; and your password is &quot; + PlayerPrefs.GetString(&quot;Password&quot;);<br>    }<br>}</pre><p>Here that is at work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*LJyeD-CZU-MmLO6eAtvdqA.gif" /></figure><p><strong>PIN</strong></p><p>Let’s move on to an example where the user enters a PIN number. The setup here is similar where the two input fields are stacked, but do not show at the same time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*T_W-gPw9q9tly7OI6ngYUw.png" /></figure><p>Let’s go ahead and set the <em>Character Limit</em> to 4, being that is the standard for most PIN numbers. The <em>Content Type</em> is also set to <em>Pin</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*d60wpeQw1-obPpdoG-RSHA.png" /></figure><p>The <em>Create Pin</em> input field uses the <em>On End Edit</em> event to ping the <em>Main Menu</em> script and the <em>Create PIN</em> function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*Ho64XftsClp9eTN2V5ECqg.png" /></figure><p>After creating a PIN, that input field hides and the <em>Enter PIN</em> input field activates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*klHqbm2lHplaqngTTqAbfQ.png" /></figure><p>The <em>Enter PIN</em> input field calls the <em>Enter PIN</em> function on the <em>Main Menu</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*VBVccd7jcEmlpenGu8YSYw.png" /></figure><p>If the created PIN is less than 4 numbers, the user will be informed and prompted to create their pin again. If the pin is 4 numbers, it is stored into the PIN variable. Because the text field is a <em>string </em>value, I need to <em>Parse </em>it into an <em>int </em>value.</p><p>When the user enters their pin, if the value doesn’t match the stored value, the user is informed to try again. If the pin entered is <em>correct</em>, the output message changes to <em>‘Correct PIN’.</em></p><pre>using System.Collections;<br>using UnityEngine;<br>using UnityEngine.SceneManagement;<br>using UnityEngine.UI;<br>using TMPro;<br><br>public class MainMenu : MonoBehaviour<br>{<br>    [SerializeField] private TMP_Text _outputText;<br>    [SerializeField] private TMP_InputField _createPINfield;<br>    [SerializeField] private TMP_InputField _enterPINfield;<br>    [SerializeField] private int _PIN;<br><br>    private void Start()<br>    {<br>        _enterPINfield.gameObject.SetActive(false);<br><br>        _outputText.text = &quot;&quot;;<br>    }<br><br>    public void Typing()<br>    {<br>        _outputText.text = &quot;Typing...&quot;;<br>    }<br><br>    public void CreatePIN()<br>    {<br>        if (_createPINfield.text.Length &lt; 4)<br>        {<br>            //you need a 4 digit pin<br>            _outputText.text = &quot;Your PIN needs to be 4 digits.&quot;;<br>        }<br>        else<br>        {<br>            _PIN = int.Parse(_createPINfield.text);<br>            _outputText.text = &quot;Your PIN Number is &quot; + _PIN.ToString();<br><br>            _createPINfield.gameObject.SetActive(false);<br>            _enterPINfield.gameObject.SetActive(true);<br>        }<br>    }<br><br>    public void EnterPIN()<br>    {<br>        if (int.Parse(_enterPINfield.text) == _PIN)<br>        {<br>            //correct PIN<br>            _outputText.text = &quot;Correct PIN&quot;;<br>        }<br>        else<br>        {<br>            //incorrect PIN<br>            _outputText.text = &quot;Incorrect PIN. Please try again.&quot;;<br>        }<br>    }<br>}</pre><p>Let’s test out too short of a PIN. Seems to be working!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*8S2r4LZSzH8jUUblGLhcdw.gif" /></figure><p>Let’s try a 4 digit PIN. 1234…nice and secure!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/1*YW3dOd0W_iPWUmfD49QehA.gif" /></figure><p>Ok, let’s enter the wrong PIN now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/397/1*RBqzlC34tVFUYU16rPdvOA.gif" /></figure><p>1234 and we are logged in!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*z7wXoBoDMFLW6hugc_phrw.gif" /></figure><p><strong>Mini-Math Game</strong></p><p>I was tasked with making a simple mini-math game using UI elements. I went way overboard and decided to include my love of RPGs and hero battlers, but for the sake of this article I will just share the UI related bits. I wanted to have a player avatar so I used a screen grab with a circular UI mask to get the look I was after. The <em>Player </em>and <em>Enemy </em>both have health bars as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/301/1*oP4AJD9WloeD0i-QYAz7hA.png" /></figure><p>The <em>Input Field</em> being used here is called <em>Answer Field</em>. The <em>Maths Text</em> will randomize the numbers and the <em>Output Text</em> will let the player know if the answer is correct.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/309/1*wK2DOUsJtQtyRFIdH3oCHQ.png" /></figure><p>Here is the designed layout for the mini-math game.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*omsCixNVlWDVJWKJuzVHvw.png" /></figure><p>My brute force solution here is not great, but I mainly wanted to get a starting point. When you run the game, the <em>Generate Problem</em> method gets called in <em>Start</em>.</p><p>I got a good laugh at myself naming this method Generate Problem, being that’s not typically something you want to do while programming…but anyways…two <em>integer </em>values are <em>randomized </em>with the <em>Get Random Int</em> method, and then sent to the <em>Texts </em>representing the numbers in the problem. The <em>answer </em>is stored for checking with the input field.</p><p>If the answer is <em>correct</em>, a sloppy <em>Coroutine </em>is started to handle the timing of the <em>player </em>shooting a magical ball at the <em>enemy</em>. If the answer is wrong, the <em>enemy </em>makes a slow sweeping chop at the <em>player</em>. <em>Correct </em>or <em>incorrect</em>, a new problem is generated.</p><pre>using System.Collections;<br>using System.Collections.Generic;<br>using UnityEngine;<br>using UnityEngine.UI;<br>using TMPro;<br>using System;<br><br>public class MathGameManager : MonoBehaviour<br>{<br>    [SerializeField] private TMP_Text _outputText;<br>    [SerializeField] private TMP_Text _mathProblemText;<br>    [SerializeField] private TMP_InputField _answerField;<br>    [SerializeField] private int _intA, _intB, _randomInt, _answer;<br>    [SerializeField] private GameObject _mathsGroup;<br><br>    public static event Action&lt;int&gt; onEnemyDamage;<br>    public static event Action onEnemyAttack;<br>    public static event Action onPlayerAttack;<br>    public static event Action&lt;int&gt;  onPlayerDamage;<br><br>    private void Start()<br>    {<br>        GenerateProblem();<br>    } <br><br>    //generate math problem<br>    public void GenerateProblem()<br>    {<br>        _outputText.text = &quot;Solve&quot;;<br>        _answerField.text = &quot;&quot;;<br><br>        _intA = GetRandomInt();<br>        _intB = GetRandomInt();<br><br>        _answer = _intA + _intB;<br><br>        _mathProblemText.text = _intA.ToString() + &quot; + &quot; + _intB.ToString() + &quot; = &quot;;<br>    }<br><br>    private int GetRandomInt()<br>    {<br>        _randomInt = UnityEngine.Random.Range(1, 25);<br>        return _randomInt; <br>    }<br><br>    //send results to the problem text<br>    //calculate and store answer<br>    public void CheckAnswer()<br>    {<br>        if (int.Parse(_answerField.text) == _answer)<br>        {<br>            _answerField.enabled = false;<br><br>            _outputText.text = &quot;Correct!&quot;;<br><br>            StartCoroutine(PlayerAttackRoutine());<br>        }<br>        else<br>        {<br>            _answerField.enabled = false;<br><br>            _outputText.text = &quot;Incorrect. Try Again.&quot;;<br><br>            //hide math ui<br>            //show enemy attack player<br>            StartCoroutine(EnemyAttackRoutine());<br>        }<br>    }<br><br>    private IEnumerator EnemyAttackRoutine()<br>    {<br>        yield return new WaitForSeconds(2f);<br><br>        //hide math ui<br>        _mathsGroup.gameObject.SetActive(false);<br><br>        onEnemyAttack?.Invoke();<br><br>        yield return new WaitForSeconds(2.5f);<br><br>        //player damage and ui<br>        onPlayerDamage?.Invoke(20);<br><br>        yield return new WaitForSeconds(3f);<br><br>        //unhide ui<br>        //generate new problem unless player is dead<br>        //unhide ui<br>        _mathsGroup.gameObject.SetActive(true);<br>        _answerField.enabled = true;<br><br>        //generate new problem unless enemy is dead<br>        GenerateProblem();<br>        //game over ui<br>    }<br><br>    private IEnumerator PlayerAttackRoutine()<br>    {<br>        yield return new WaitForSeconds(2f);<br><br>        //hide math ui<br>        _mathsGroup.gameObject.SetActive(false);<br><br>        //show player attack enemy<br>        onPlayerAttack?.Invoke();<br><br>        yield return new WaitForSeconds(1.2f);<br><br>        //enemy damage ui and animation<br>        onEnemyDamage?.Invoke(20);<br><br>        yield return new WaitForSeconds(2f);<br><br>        //unhide ui<br>        _mathsGroup.gameObject.SetActive(true);<br>        _answerField.enabled = true;<br><br>        //generate new problem unless enemy is dead<br>        GenerateProblem();<br>        //you win ui<br>    }<br>}</pre><p>I must be really terrible at math. Ouch!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*CjzikGUIfv-n6LtCcD7GFQ.gif" /></figure><p>Take that dark soul!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*Y-91RwVcVUIFuxo8yyh2rg.gif" /></figure><p>I added an on death animation to the enemy because well, it was pretty unsatisfying not having him eventually keel over.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*tefBI2B6UGJtWKT7oeX5bw.gif" /></figure><p>If you made it this far, thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20cd45dd9c1c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>