<?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 Shane Smith on Medium]]></title>
        <description><![CDATA[Stories by Shane Smith on Medium]]></description>
        <link>https://medium.com/@shanesmith822?source=rss-f082303a0527------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Shane Smith on Medium</title>
            <link>https://medium.com/@shanesmith822?source=rss-f082303a0527------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 14:58:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shanesmith822/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[Delegates And Events In Unity]]></title>
            <link>https://medium.com/@shanesmith822/delegates-and-events-in-unity-e3bc40cd78c5?source=rss-f082303a0527------2</link>
            <guid isPermaLink="false">https://medium.com/p/e3bc40cd78c5</guid>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[delegates-and-events]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Shane Smith]]></dc:creator>
            <pubDate>Sun, 29 Jun 2025 01:40:34 GMT</pubDate>
            <atom:updated>2025-06-29T01:40:34.376Z</atom:updated>
            <content:encoded><![CDATA[<p>This is going to be a long article, but it is worth it.</p><p>DELEGATES</p><p>A delegate is a variable that can hold multiple methods.</p><p>In order to create a delegate, we have to declare it using the keyword like this:</p><pre>public delegate void myMethod;</pre><p>Now, for each delegate, the ending signature has to match. If I make a delegate that takes a parameter, I would have to make a function that has a parameter in order to use that delegate.</p><pre><br>public delagate void OnChangeColor(color ColorChange)<br></pre><p>With this, I can use the delegate as a variable like this:</p><pre>public OnChangeColor changed;</pre><p>I will now have to create the method that matches the delegate or it will throw an error.</p><p>How do I use the delegates for a script and invoke it?</p><p>We will use them by assigning them to its appropriate method with matching signatures. For ones with no method signature(parameter), we can make sure that the delegate is not null, if so, then invoke the delegate.</p><pre><br>    public delegate void OnChangeColor(Color newColor);<br>    public OnChangeColor change;<br><br>    public delegate void OnComplete();<br>    public OnComplete complete;<br><br>    void Start()<br>    {<br>        change = ChangeColor;<br>        change(Color.blue);<br>        complete = Completion;<br>    }<br>    void ChangeColor(Color color)<br>    {<br>        print(&quot;Changing color to&quot; + color.ToString());<br>    }<br>    void Completion()<br>    {<br>        Debug.Log(&quot;It is done&quot;);<br>    }<br>}</pre><p>Result: (do not forget to make sure to assign the script to a game object)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DNgG-A9q0bu3xD_N9bJJrg.png" /></figure><p>We can also subscribe and unsubscribe to multiple delegates, we just have to use the plus or minus signs when we are adding tasks like this:</p><pre>public class Main : MonoBehaviour<br>{<br>    public delegate void OnChangeColor(Color newColor);<br>    public OnChangeColor change;<br><br>    public delegate void OnComplete();<br>    public OnComplete complete;<br><br><br><br>    void Start()<br>    {<br>        change = ChangeColor;<br>        change(Color.blue);<br>       // complete = Completion;<br>        complete += Task1;<br>        complete += Task2;<br>        complete -= Task3;<br>       <br>        if (complete != null)<br>        {<br>            complete();<br>        }<br>      <br>    }<br><br>    void ChangeColor(Color color)<br>    {<br>        print(&quot;Changing color to&quot; + color.ToString());<br>    }<br><br>   // void Completion()<br>    //{<br>        //Debug.Log(&quot;It is done&quot;);<br>    //}<br><br>    void Task1()<br>    {<br>        Debug.Log(&quot;Task 1 is complete&quot;);<br>    }<br>    void Task2()<br>    {<br>         Debug.Log(&quot;Task 2 is complete&quot;);<br>    }<br>    void Task3()<br>    {<br>         Debug.Log(&quot;Task 3 is complete&quot;);<br>    }<br>}</pre><p>The only changes I made was to create three more methods (task 1, task 2, and task 3) and added those methods into the start function. Now the result show only show the color and two tasks complete:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WxiutKH7ZbbZbgSDfHwc7A.png" /></figure><p>This is called a multicast delegate, where multiple methods can be invoked at one time.</p><p>EVENTS:</p><p>Events are a type of multicast delegate that allows communications between scripts within its own class.</p><p>Events are better to use than delegates because with delegates, classes can access and modify the function of the delegate. Events have inherent security, meaning that they are only accessed and triggered from their own class. Other scripts can only subscribe and unsubscribe from the events.</p><p>For Example: I want to make objects move up in specified units.</p><p>I created a scene with three spheres and a button. I added rigidbodies to the spheres and turned off gravity. I also added a button on the bottom with a canvas, and I did not name it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aFgAn95G6WCr5J7zWRUV0Q.png" /></figure><p>I will have to create two scripts for this.</p><p>First one, I made a script called Main2. I made a delegate void called OnThisClick. I created an event from a delegate and named it onClick.</p><p>I made a void and named it ButtonClick. For this I did the shorthand for invoking a method. It is the same as, “if the event is not null, invoke it”.</p><pre>public class Main2 : MonoBehaviour<br>{<br>    public delegate void OnThisClick();<br>    public static event OnThisClick onClick;<br>    public void ButtonClick()<br>    {<br>        onClick?.Invoke();<br>    // if(onClick != null)<br>    // {<br>         //onClick();<br>    // }<br>    }<br>}</pre><p>I put this script on a gameObject in the scene and made the button access this method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Z6dLjbJojLmk0TRD-ETkg.png" /></figure><p>Second, I created another script and called it MoveSphere.</p><p>I made two variables, one called positionX and a serialized field called distance.</p><p>In the start method, I made the positionX equal to the transform.position.x, so that this value cannot be changed and sets the position. I subscribed to the event from the Main2 script and equaled it to the MoveUp method.</p><p>In the MoveUp method, I made the transform equal to a new vector3, which consists of the positionX value, the distance value, and 0 on the z-axis.</p><pre>public class MoveSphere : MonoBehaviour<br>{<br>    [SerializeField] float distance;<br>    float positionX;<br>    // Start is called before the first frame update<br>    void Start()<br>    {<br>        positionX = transform.position.x;<br>        Main2.onClick += MoveUP;<br>    }<br><br>    public void MoveUP()<br>    {<br>     <br>        transform.position = new Vector3(positionX, distance, 0f);<br>    }<br>}</pre><p>I equipped all of the spheres with this script and can set up individual distances values from the editor. I put 1.5 for the first sphere, 3.5 for the second one, and 5.5 for the last one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dOK4A_IEDwd5hQ39nuY13A.png" /></figure><p>Result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J_NM8AqiON7DFDFKWC1T5w.gif" /></figure><p>Remember, if the script is destroyed or deactivated, unsubscribe from an event because it can cause memory leaks.</p><p>ACTIONS:</p><p>Actions are delegates that are triggered by utilizing callbacks. This can handle inputs from the player. We can create an event by using one line of code.</p><p>Actions return a void type, meaning that they do not hold values.</p><p>In order to use the actions, we have to use the System namespace and add brackets when we declare it like this:</p><pre>using System;<br>public class Main3 : MonoBehaviour<br>{<br>  public Action onComplete; // brackets only if you want to add parameters<br> // public Action&lt;int&gt; completionAmount; // Like this<br>/// other code here<br><br>  <br>  void Start()<br>  {<br>    onComplete += CompleteTask;<br>  }<br>  public void CompleteTask()<br>  {<br>    onComplete?Invoke();<br>  }<br><br>}</pre><p>Actions are type-safe, meaning that there will be no errors if using the variables are using defined values or types.The compiler validates types before continuing, otherwise we will get an error.</p><p>Since C# is type-safe , it means that the errors will be caught while compiling and will stop running if it spots one. With this, debugging is easier, makes code readable and performant.</p><p>I made 3 more objects for the next example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_5B3dQSDPNmpnmd5Cjhfrg.png" /></figure><p>Example: I recreated the Main3 script and I will use it to change any declared color.</p><p>I made a private color variable called newColor and created an Action called ChangeColor that holds a color variable.</p><p>In update, I assigned the D keyboard to invoke the ChangeColors method.</p><p>In the Change Colors method, I made a local color variable named, newCol. if the action ChangeColor is not null, then we invoke the event with the local variable. I also made the local color variable equal to the private color variable.</p><pre>public class Main3 : MonoBehaviour<br>{<br>    private Color newColor;<br>    public static Action&lt;Color&gt; ChangeColor;<br>    // Start is called before the first frame update<br>    <br>    void Update()<br>    {<br>         if (Input.GetKey(KeyCode.D))<br>        {<br>            ChangeColors(newColor);<br>        }<br>    }<br>    // Update is called once per frame<br>    void ChangeColors(Color newCol)<br>    {<br>        newColor = newCol;<br>        if (ChangeColor != null)<br>        {<br>            ChangeColor(newCol);<br>        }<br>    }<br>}</pre><p>I made another script called, ChangeColors and I will explain briefly.</p><p>I made a MeshRenderer variable named mesh and made a serialized field for color named newCol.</p><p>In the Start Function, I got the MeshRenderer component.</p><p>On Enable, I subsribed the Action to the GetNewColor Method.</p><p>On the GetNewColor method, I made sure to make the local color variable equal to the serialized color variable, newCol.</p><p>Next, I made the mesh material color equal to the local variable, named color.</p><pre>public class ChangeColors : MonoBehaviour<br>{<br><br>    MeshRenderer mesh;<br>    [SerializeField] private Color newCol;<br>    // Start is called before the first frame update<br>    void Start()<br>    {<br>        mesh = GetComponent&lt;MeshRenderer&gt;();<br><br>        <br>    }<br>    void OnEnable()<br>    {<br>        Main3.ChangeColor += GetNewColor;<br>    }<br><br>    // Update is called once per frame<br><br>    public void GetNewColor(Color color)<br>    {<br><br>        color = newCol;<br>        mesh.material.color = color;<br>    }<br>}</pre><p>Equip the ChangeColors Script to the cubes in the example. I made one cube turn red, another cube turn green, and one to turn blue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*37UDJJ9G8xO5HAMUghPJ2A.png" /></figure><p>Make sure that the Main3 script is equipped on a gameObject.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*BvNRxKIp-xTgDYa59YBGgg.png" /></figure><p>If I press D, it should change each cube to their assigned colors.</p><p>Result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zHQ1ieYFAb_8adhARubd6A.gif" /></figure><p>RETURN TYPE DELEGATES</p><p>There is a difference between void type delegates and return type delegates.</p><p>Void type delegates will perform actions without any callbacks or values.</p><p>Return Delegates will perform actions with a value and run the code with the specified variable.</p><p>In order to use Func, a Functional Delegate, we have to use the System namespace again.</p><p>Example: I want to count how many objects there are on the game. I made six cubes for this example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*62dqNcHHdJ5CfOG_e_T0bg.png" /></figure><p>I created a Main4 Script. I created an array named cubes and made a private int variable named count.</p><p>I made a public Func that takes a parameter of an array of GameObjects and will return an int variable.</p><p>In the start method, I made the countCubes Func subscribed to the GetCubeCount Int method. The private count variable will equal to the CountCubes Func that holds the GameObject array. For the final touch, I did a Debug.Log that will show the count variable with a concatenated string.</p><p>For the GetCubeCount, it will return an int value and it takes the GameObject array parameter. It will return the amount of the cubes.</p><pre>using UnityEngine;<br>using System;<br><br>public class Main4 : MonoBehaviour<br>{<br>    [SerializeField] GameObject[] cubes;<br>    int count;<br>    <br>    public Func&lt;GameObject[], int&gt; CountCubes;<br>    // Start is called before the first frame update<br>    void Start()<br>    {<br><br>        CountCubes = GetCubeCount;<br><br>        count = CountCubes(cubes);<br>        Debug.Log(&quot;Count = &quot; + count);<br><br>    }<br><br>    // Update is called once per frame<br>    int GetCubeCount(GameObject[] name)<br>    {<br><br>        return cubes.Length;<br>    }<br>}</pre><p>Attach this script on a game object and drag the objects from the scene into the elements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*UJEx_Kybqiq4w09NkKYZdw.png" /></figure><p>There should be 6 cubes on here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*k2K2EAG4Cu-UThy2MMDMsA.png" /></figure><p>When I run the game, there should be a debug log that will say how many cubes on there.</p><p>Result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/1*4QQccyyDsnE_1EstdvBgvA.png" /></figure><p>LAMBDA</p><p>Using Lambda expressions can simplify some methods. A Lambda is a function that can be defined and executed without a name.</p><p>How to use the LAMBDA expression is that you combine an equal sign and a right hand sign( =&gt;) and it means “Go To”.</p><p>Using the same example, I can comment out the int method and pass it without naming it.</p><p>I commented out the bottom and made a new method with the CountCubes Func. Make a parenthesis and add a local variable that matches the variable for the Func, use the “Go To” arrow, and pass in Names.Length. The function knows it needs an array and because the return type is an int, I was simply able to get the amount of objects in the array using the local variable name.</p><pre>using UnityEngine;<br>using System;<br><br>public class Main4 : MonoBehaviour<br>{<br>    [SerializeField] GameObject[] cubes;<br>    int count;<br>    <br>    public Func&lt;GameObject[], int&gt; CountCubes;<br>    // Start is called before the first frame update<br>    void Start()<br>    {<br><br>        CountCubes = (names) =&gt; names.Length;<br><br>        count = CountCubes(cubes);<br>        Debug.Log(&quot;Count = &quot; + count);<br><br>    }<br><br>    // Update is called once per frame<br>    //int GetCubeCount(GameObject[] name)<br>    //{<br>  <br>        //return cubes.Length;<br>   // }</pre><p>The result should still be the same when I run the game.</p><p>I will make an article about the practice with Delegates and events. This article is long.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3bc40cd78c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Use Singletons In Unity]]></title>
            <link>https://medium.com/@shanesmith822/how-to-use-singletons-in-unity-4bc5bbd74393?source=rss-f082303a0527------2</link>
            <guid isPermaLink="false">https://medium.com/p/4bc5bbd74393</guid>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[software-developement]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Shane Smith]]></dc:creator>
            <pubDate>Sat, 28 Jun 2025 07:47:43 GMT</pubDate>
            <atom:updated>2025-06-28T07:47:43.632Z</atom:updated>
            <content:encoded><![CDATA[<p>A singleton is a global class in Unity that can only appear once in the scene. These are generally used if you want to manage events in the game and ensures that the code can be easily communicated.</p><p>Example: I will make a singleton for my UI Manager Class:</p><p>Note: There are different ways to make a singleton, I chose this one way.</p><p>I made a private static variable and a public static variable of the UIManager instance. This is similar to using gets and sets.</p><p>When the other scripts in the project need to access The UI Manager, then the scripts will get the component by Instance variable (uppercase I).</p><p>On awake, if this instance (this gameObject) is not null and if it is not this certain one, then delete it. Then if that is not the case, then we can make the instance equal to this copy of the gameObject.</p><p>In order for it to move from one scene to another, we use DontDestroyOnLoad() which allows data to transfer from one scene to another without being deleted. This is not necessary for a singleton, unless this singleton is going to be used across multiple scenes.</p><pre>using System.Collections;<br>using UnityEngine;<br>using UnityEngine.UI;<br>using System;<br><br>public class UIManager : MonoBehaviour<br>{<br>private static UIManager _instance;<br> public static UIManager Instance;<br><br> <br> <br> void Awake()<br>    {<br>        if (_instance != null &amp;&amp; _instance != this)<br>        {<br>            Destroy(gameObject);<br>        }<br>        else<br>        {<br>            _instance = this;<br>        }<br>    }<br><br>    private void Start()<br>    {<br>        DontDestroyOnLoad(gameObject);<br><br>    }<br><br>    /// some code here<br>    public void FadeInBlack()<br>    {<br>      // some more code here<br>    }<br><br><br>}</pre><p>For example, if I need the scene to load using a fade effect with another script like an entrance script, I can get the function of the UIManager like this:</p><pre>using System.Collections;<br>using UnityEngine;<br>using UnityEngine.UI;<br>using System;<br>using UnityEngine.SceneManagement;<br><br>public class Entrance : MonoBehaviour<br>{<br>  int anyNumberHere;<br> <br>  void LoadScene()<br>  {<br>   <br>     UIManager.Instance.FadeInBlack();<br><br>      SceneManager.LoadScene(anyNumberHere);<br>  <br>  }<br>}</pre><p>Note: Excuse the bad code… I was just making an example for this case use.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4bc5bbd74393" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using the Unity Profiler]]></title>
            <link>https://medium.com/@shanesmith822/using-the-unity-profiler-3bac222ad029?source=rss-f082303a0527------2</link>
            <guid isPermaLink="false">https://medium.com/p/3bac222ad029</guid>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <dc:creator><![CDATA[Shane Smith]]></dc:creator>
            <pubDate>Fri, 27 Jun 2025 05:29:38 GMT</pubDate>
            <atom:updated>2025-06-27T22:00:41.432Z</atom:updated>
            <content:encoded><![CDATA[<p>This is an article on how I learned to use the Unity Profiler.</p><p>First, I went to the window and I went to the analysis panel and selected profiler.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*oa8sPBpjBp9AhjIq5EO3Ww.png" /></figure><p>For this example, I am using a school project for this lesson.</p><p>For this, we can see many different profiles. This particular category deals with the CPU usage. We can see what affects the CPU such as scripts, physics, animation, GC, UI, Rendering and more. The categories have their own profile, so we can check for any other specific issues with the profiler.</p><p>We can enable or disable which spikes to look for. This is the area on where we will figure out what causes the frame rate to spike.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0WlYd6AWNLxcvE5Ku9XONQ.png" /><figcaption>This is the play mode, but I will address the spikes a little later</figcaption></figure><p>This window for rendering deals with batch counts, draw calls, and polygon counts for meshes. A draw call is when a message (or call) is given to the GPU to create a specific object and/or material. It uses the data from the CPU and sends it to the GPU for a physical rendering of the object. Example, the CPU can send data for a material such as color, texture, shader information, etc, and then the GPU attempts to physically render the material. A batch is a group of draw calls that are combined to reduce the amount of produced objects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1eJ43o1zJ1oysC7EhvCzPw.png" /></figure><p>Memory deals with the allocation of memory and how it is being used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W99JxN3c4c0PSVqt-lJdGg.png" /></figure><p>Audio deals with the amount of sounds playing at one time and also any other irregularities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3BmSAQPE8SpgaS54bFn02A.png" /></figure><p>UI covers any physical issues and how it performs. There is another menu call UI Details and it goes further into the UI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b1SyeGZ2UMsBJnGs60P55g.png" /><figcaption>There are tiny spikes here because I have some empty canvas objects that are place holders</figcaption></figure><p>There is a timeline on where you can see what is fluctuating in each time frame.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Z4ykxchcHuTqagSBpg0JQ.png" /></figure><p>We will switch it to the hierarchy for easier reading. As you can see, there is the fluctuation in the EditorLoop and in the profiler. (Not seen here, but I had main player issues as well).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UT5kVtKF4QbpTQIE3AY0uQ.png" /></figure><p>By clicking on the profiler modules tab, we can enable any window we want to see and there are other choices such as the GPU (Graphics), Physics 2D, and more. I do not need most of these, but I have multiple audio sources, UI, and more. I would need memory to see if the objects or UI are being used properly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*LDiBYxQdIxIofe3AwwegQg.png" /></figure><p>The reason for those green spikes is because the editor takes a lot of processing power, but I heard that choosing another layout can solve this issue as well (which did solve some of the issues by using the default layout and it did increase the frame rate, but there are still some spikes). For right now, we are testing everything out, but I will get to it.</p><p>There is a menu on the profiler, and I will briefly mention it. The “Play Mode” drop-down will analyze the mode it is in. You can also click it and switch this to “Edit Mode”. You can record the analysis with the red circle, there is the amount of frames passed with the frame number and we can also skip, pause, and stop frames. There is the clear button, the clear on play button, which can be enabled/disabled. The deep profile button allows the profiler to collect detailed data about each spike and that we can enable. There is the call stacks drop-down and for now, it is checked for garbage allocation. We can save the information and load binary information according the icons at the bottom.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rp8NL29sUibHleVYv-v-fA.png" /></figure><p>A stack trace is a log or report that occurs during runtime that showcases a sequence of function calls that happened before the error occurred in the code. It is similar to the warning you receive when you have a null reference to an object. When we get the component, the scripts executes to find the object, and if there is no object, then the object is considered null and it throws an error.</p><p>For example(This project is a turn-based combat): This is an error that occurred, because the next person that was supposed to hit or to be hit, died or do not exist.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dAWnwkUhnI4VBEy-4FP4Fg.png" /><figcaption>The message on the bottom is a stack trace, while the highlighted area is an error. This is an array error.</figcaption></figure><p>THE PROBLEM:</p><p>When I entered play mode, I paused the area to one of the spikes. I see that the “PlayerLoop” had a GC allocation of 368 bytes. It made the frames drop, although everything else was fine. This was another problem that I had in this school project (besides the inventory problem). There are three instances of the loop sample that are being called.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yPMYzvUGZ-NNrfpwqn-EnA.png" /><figcaption>I am using Unity 2022.3.5.1, so this window is a little different. Make sure the Deep profile and the Call Stacks are enabled at the top.</figcaption></figure><p>There is another window called Related Data and it gives you more information concerning which object the function or data it is associated with. It is mostly the same, it just gives the name of the object. Also, in the “Related Area” tab, there are three dots. It can allow you to see the full method names on the information. It is shortened by default.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xmYYIZZ6wp_w0Fvb1JX0GQ.png" /></figure><p>I went to the PlayerLoop drop-down to see what was taking so much bytes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yueEOTr8u31KoStavTENCA.png" /></figure><p>I scrolled further until I saw this area. I highlighted GUI.Repaint. This is called when the GUI is redrawn from the OnGUI function, specifically from an event called Event.Repaint (from Unity sources). This is an UI issue. It did not show much from the UI profile, but it did effect performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TmTULgv3N15zljjBeB2ohQ.png" /></figure><p>Scrolling further, I saw that there were 2 instances of the GUI layout being called, but the second call was empty. I went further into the drop-down and saw the allocation from a layout group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IbMiH74yBFX2F2Qcqvbvwg.png" /></figure><p>From both of these, I seen that it was not associated with any object, so I figured it was from a script. I seen that the GUIUtility.BeginGUI function had a huge allocation of 288 bytes with 2 call stacks. A call stack is a log of information that is gathered when functions and methods are executed in your scripts. A call stack shows function information such as variables, parameters, name, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sWrTQvBv9OurZqWsPplchg.png" /></figure><p>I will make another article for this solution. With this information, I know how to get some details on what is affecting my performance.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3bac222ad029" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adding a Re-spawn effect to my Space Shooter:]]></title>
            <link>https://medium.com/@shanesmith822/adding-a-re-spawn-effect-to-my-space-shooter-0840d7b7c61a?source=rss-f082303a0527------2</link>
            <guid isPermaLink="false">https://medium.com/p/0840d7b7c61a</guid>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[unity2d]]></category>
            <dc:creator><![CDATA[Shane Smith]]></dc:creator>
            <pubDate>Sat, 03 May 2025 00:16:45 GMT</pubDate>
            <atom:updated>2025-05-03T00:17:58.893Z</atom:updated>
            <content:encoded><![CDATA[<p>I wanted to add a re-spawn effect like the old games. Thanks to many tutorials, specifically the one on Udemy (thanks Paul!).</p><p>First, in my Player Script, I added a new header, named Spawn Time, and two float variables named spawnTime, invincibleTime, and a Vector3 variable called currentPosition. I made the vector public for now. The spawn time, is how long the total spawn time will be or when the player appears, while the invincibleTime will determine how long the player cannot be hit. The vector3 current position will store the position and spawn in the last place it was before being hit.</p><pre><br>    [Header(&quot;SpawnTime&quot;)]<br>    [SerializeField] float spawnTime = 2f; <br>    public Vector3 currentPosition; // for now<br><br>    [SerializeField] float invincibleTime;</pre><p>In my Start function, I added this code to store the player’s position:</p><pre> currentPosition = transform.position;</pre><p>Then, in my Player script, I made a coroutine called Respawn() in the TakeDamage() function.</p><pre>        lives--;<br>        StartCoroutine(Respawn());<br>         _uiManager.UpdateLives(lives);</pre><p>In the Respawn Coroutine, I added some code. I will instantiate the explode object into the player’s position. I will get the collider using getComponent and disable it. The player will be unable to fire, the SpriteRenderer is disabled, and the thrusters are inactive.</p><pre> private IEnumerator Respawn()<br>    {<br>        <br>        Instantiate(explodeObject, transform.position, Quaternion.identity);<br>        Collider2D collide = gameObject.GetComponent&lt;Collider2D&gt;();<br>        collide.enabled = false;<br>        isFiring = false;<br>        spriteRend.enabled = false;<br>        _thrusters.SetActive(false);<br>    <br><br>   </pre><p>In this next area, if the lives are equal to 2, then the right hit effect is set to false. If the lives are equal to 1, then both the left and right hit effects are inactive. I set the game object layer to number 7. The player’s layer is number 6, while the enemy layer is number 7 on my layers tab.</p><pre>        if (lives == 2)<br>        {<br><br>            _rightHitShip.SetActive(false);<br>        }<br>        if (lives == 1)<br>        {<br><br>            _rightHitShip.SetActive(false);<br>            _leftHitShip.SetActive(false);<br>        }<br>        gameObject.layer = 7;</pre><p>For this set of code, I made a new yield with WaitForSeconds with the spawn time variable. The player will appear after the spawnTime ends. This value is how long the player will be out of frame.</p><p>The current position is equal to the player’s transform.position. Setting the vector value this way ensures that the player will appear at the last position it was in before the hit.</p><p>If transform.position is equal to the currentPosition, it will be positioned to the area from the first time you started the game.</p><p>For the amount of invincibleTime, I looped through the sprite renderer each time by 0.1 enabling and disabling with a float value by 0.1 with waitForSeconds.</p><pre>        yield return new WaitForSeconds(spawnTime);<br><br>        currentPosition = transform.position;<br><br>        for (float i = 0; i &lt; invincibleTime; i += 0.1f)<br>        {<br><br>            spriteRend.enabled = !spriteRend.enabled;<br>            yield return new WaitForSeconds(0.1f);<br>        }</pre><p>For this end, I reactivated the hit effects after the loop ends. I reactivated the right thruster after life 2 and the left/right hit effects on life 1.</p><pre>        if (lives == 2)<br>        {<br>            _rightHitShip.SetActive(true);<br>        }<br>        if (lives == 1)<br>        {<br>            _rightHitShip.SetActive(true);<br>            _leftHitShip.SetActive(true);<br>        }</pre><p>For this last bit of code, I enabled the collider and enabled the sprite renderer. I made the player able to fire, set all of the thrusters to true. I set the object back to its own player.</p><pre>        collide.enabled = true;<br>        spriteRend.enabled = true;<br>        isFiring = true;<br>        _thrusters.SetActive(true);<br>        gameObject.layer = 6;<br>    }</pre><p>At last, set the values of the spawn time and the invincible time. I made them equal, but the perfect values for me are: spawnTime-2f and invincibleTime-2f.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*fR8e03wt-uS010zuFc6Xmg.png" /></figure><p>Result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*BYDNqeDSXOV6LpYBKIDmcw.gif" /></figure><p>That is the end of this article. (disabled animations for now on the thrusters and being hit).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0840d7b7c61a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating Hazards in the 2D Space Shooter Part 2]]></title>
            <link>https://medium.com/@shanesmith822/creating-hazards-in-the-2d-space-shooter-part-2-86779cf43773?source=rss-f082303a0527------2</link>
            <guid isPermaLink="false">https://medium.com/p/86779cf43773</guid>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[unity2d]]></category>
            <dc:creator><![CDATA[Shane Smith]]></dc:creator>
            <pubDate>Thu, 01 May 2025 07:28:57 GMT</pubDate>
            <atom:updated>2025-05-03T05:52:34.343Z</atom:updated>
            <content:encoded><![CDATA[<p>From where we left off, I will now show the meteor behavior script.</p><p>EXPLOSION</p><p>For the explode prefab, I made a quick explosion using the particle system.</p><p>(If you want the tutorial, here it <a href="https://www.youtube.com/watch?v=adgeiUNlajY">is</a>. It is about a little over 12 minutes long, but this guy teaches you how to create it in the VFX and with the particle system. Watch about the first 5 minutes.)</p><p>With a slight bit of creativity, I added debris in the explosion, which are various amounts and sizes of square pieces (I will reuse it for another object I am creating later).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*RUG_dAByJ6mYc6fc9xF6DQ.png" /><figcaption>This is when the explosion prefab was instantiating multiple copies at one time due to wrong code execution.</figcaption></figure><p>This is how it looks, when it is not instantiating wildly in the scene:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*mC9ONgGZtZGdElhA_c_xlg.png" /><figcaption>This is when the explosion is starting.</figcaption></figure><p>Here it is when it is almost done exploding:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*g2iM1mdRHeRhicqkaaGxJQ.png" /><figcaption>This is the explosion is almost complete.</figcaption></figure><p>Note: Make sure when you follow the tutorial, have the universal render pipeline pack downloaded in your project or created your project with it.</p><p>After this, I made the explosion into a prefab and attached a small script called DestroyObject.</p><p>I made a serialized float called effectTime, and made a variable for the AudioSource with the naming being similar.</p><pre>public class DestroyObject : MonoBehaviour<br>{<br>    [SerializeField] float effectTime;<br>  AudioSource audioSource;</pre><p>In the Awake function, I used getComponent for the AudioSource.</p><pre>void Awake()<br>    {<br>        audioSource = GetComponent&lt;AudioSource&gt;();<br>    }</pre><p>In the start function, I made the audiosource play and destroy itself, with the effectTime float as the delay. It is set to 2 because the explosion I created with the tutorial lasts 2 seconds.</p><pre>void Start()<br>    {<br>        audioSource.Play();<br>        Destroy(this.gameObject, effectTime);<br>    }<br>}</pre><p>I imported another sound from the asset pack I bought from <a href="https://kenney.nl/">this</a> company. it is the “low_FrequencyExplosion_000.ogg”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/160/1*91NcapF_smq4sz5d1bItVQ.png" /></figure><p>METEOR BEHAVIOR</p><p>Now, create a script called MeteorBehavior.</p><p>I made a serialized field to get a gameObject, called explodeParticlePrefab.</p><p>I made a private reference for the player.</p><pre>public class MeteorBehavior : MonoBehaviour<br>{<br>    [SerializeField] GameObject explodeParticlePrefab;<br>    private Player _player;</pre><p>I made a reference to the player in the Start Function by using the FindGameObjectwithTag function and getting the Player Script.</p><pre>void Start()<br>    {<br>        _player = GameObject.GameObjectWithTag(&quot;Player&quot;).GetComponent&lt;Player&gt;();<br>    }</pre><p>In the Update function, if the object goes further then the y boundary (set when we made the player boundary), then we destroy the object.</p><pre>void Update()<br>    {<br>        if (transform.position.y &lt; -9.3f)<br>        {<br>            Destroy(this.gameObject);<br>        }<br>    }</pre><p>I set the collider into a trigger. If the object is hit by a laser or an explosive (for all of my weapons such as the missile and another weapon I am creating to replace the “Big Cannon” ), then we destroy the object and and it will instantiate the explode object. If it hits the player, then the player will take damage, and the meteor will explode.</p><pre>private void OnTriggerEnter2D(Collider2D other)<br>    {<br>        if (other.CompareTag(&quot;Laser&quot;)  || other.CompareTag(&quot;Explosive&quot;) )<br>        {<br>            Destroy(other);<br>            ExplodeObject();<br>        }<br>        if (other.CompareTag(&quot;Player&quot;))<br>        {<br>            if (other != null)<br>            {<br>                _player.TakeDamage();<br>            }<br>            ExplodeObject();<br>        }</pre><p>I made a small method for ExplodeObject() that will instantiate the prefab, and destroy the game object.</p><pre>public void ExplodeObject()<br>    {<br>        Instantiate(explodeParticlePrefab, transform.position, transform.rotation);<br>        Destroy(gameObject);<br>    }<br>}</pre><p>Make sure you find the prefab we just created and apply it to the object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/508/1*BoVOzrtXBG0zw1XBu_uH_w.png" /></figure><p>Result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*Iu-7jFsXC74b3roojbBU1g.gif" /></figure><p>This is the end of this article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86779cf43773" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating Hazards in the 2D Space Shooter Part 1]]></title>
            <link>https://medium.com/@shanesmith822/creating-hazards-in-the-2d-space-shooter-part-1-c8b392d48bea?source=rss-f082303a0527------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8b392d48bea</guid>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[unity2d]]></category>
            <dc:creator><![CDATA[Shane Smith]]></dc:creator>
            <pubDate>Thu, 01 May 2025 07:25:47 GMT</pubDate>
            <atom:updated>2025-05-02T05:45:08.694Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a 2-part article that explains how to move objects and create hazards for the space shooter.</p><p>I will create meteors. There is a difference between asteroids, comets, and meteors, and meteoroids. According to this small <a href="https://www.nasa.gov/directorates/smd/whats-the-difference-between-asteroids-comets-and-meteors-we-asked-a-nasa-scientist-episode-16/">article</a>, an asteroid is a rock, comets are made of ice and dust, and a meteoroid is created when something collides with either, a comet or an asteroid.</p><p>Meteors, are the ones that will only come in a downward direction and crashes down when it hits a planet.</p><p>I duplicated (for now) the asteroid object, decreased them in various sizes and colored them dark brown.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*kLgOBrUUDguwhtC0wLnGcw.png" /></figure><p>Next, I created 2 scripts, which one can be used on any object.</p><p>First, I will create a script called Mover.</p><p>I made a variable for the rigidbody2D named rig and two serialized bools named canMove and canRotate.</p><p>I also made two private floats for speed and rotation named, _speed and _rotateSpeed respectively.</p><p>I made two serialized floats for default speed and default rotation with the naming being similar, defaultSpeed and defaultRotation.</p><pre>public class Mover : MonoBehaviour<br>{    <br>    private Rigidbody2D rig;<br>    [SerializeField] bool canRotate;<br>    [SerializeField] bool canMove;<br>    float _speed;<br>    [SerializeField] float defaultSpeed = 1.5f;<br>````float _rotateSpeed;<br>    [SerializeField] float defaultRotation = 45f;</pre><p>I used getComponent for the 2D rigidbody.</p><pre>void Start()<br>    {<br>        rig = GetComponent&lt;Rigidbody2D&gt;();<br>    }</pre><p>I set the clamps for the speed and rotation in the Update method. you can set it to any rotation you want, but those numbers are perfect for me.</p><p>Now, in the Update function, if we set the canMove bool to true, then we make the _speed variable equal to the defaultSpeed variable. we also set the velocity with the _speed variable multiplied with time.deltaTime and Vector3.down direction. It is the same, for the canRotate bool. If the canRotate bool is set to true, then we will use the angularVelocity to rotate and set _rotateSpeed equal to defaultRotation.</p><pre>void Update()<br>    {<br>        defaultSpeed = Mathf.Clamp(defaultSpeed, 0f, 20f);<br>        defaultRotation = Mathf.Clamp(defaultRotation, -90f, 90f);<br>        if (canMove)<br>        {<br>            _speed = defaultSpeed;<br>            rig.velocity = _speed * Time.deltaTime * Vector3.down;<br>        }<br>        if (canRotate)<br>        {<br>            _rotateSpeed = defaultRotation;<br>            rig.angularVelocity = _rotateSpeed;<br>        }</pre><p>If the canMove bool is false, then we set the speed and velocity to zero. Same with the canRotate bool, if it is false, we set the _rotateSpeed and angularVelocity to zero.</p><pre>        <br>        else<br>        {<br>            if (!canMove)<br>            {<br>                _speed = 0f;<br>                rig.velocity = Vector3.zero;<br>            }<br>            if (!canRotate)<br>            {<br>                _rotateSpeed = 0f;<br>                rig.angularVelocity = 0f;<br>            }<br>        }<br>    }<br>}</pre><p>Result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_3vez-E1trErT3BmrAk_ow.gif" /></figure><p>Note: I cut out a part of my gif that showed me manipulating the speed variable.</p><p>Next Part: The meteor behavior script seen on here.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8b392d48bea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up Unity for AR Development]]></title>
            <link>https://medium.com/@shanesmith822/setting-up-unity-for-ar-development-52e61c4ef3c8?source=rss-f082303a0527------2</link>
            <guid isPermaLink="false">https://medium.com/p/52e61c4ef3c8</guid>
            <category><![CDATA[unity-xr]]></category>
            <category><![CDATA[unity-ar]]></category>
            <category><![CDATA[ar-development]]></category>
            <dc:creator><![CDATA[Shane Smith]]></dc:creator>
            <pubDate>Tue, 01 Apr 2025 20:32:34 GMT</pubDate>
            <atom:updated>2025-04-01T20:32:34.667Z</atom:updated>
            <content:encoded><![CDATA[<p>I am going to build the game for the IOS build since I have a phone, computer, and tablet that have Apple operating systems.</p><p>When I downloaded Unity and downloaded the AR template in 2022.3.5, I found that everything was already included, even if I wanted to build with Android.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2I82lRFsv_kIX_7SAm-4Pw.png" /></figure><p>I typed in “AR” in the package manager and I saw this list. Everything that I could possibly use is already installed or I can add the ability to install, such as publishing the project using WebGL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3eFhKlP51rgnsNKke0L_SA.png" /></figure><p>In the build settings, I made sure that the target platform was set to macOS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s46IqXY6YK-ZbCiINExWkg.png" /><figcaption>I switched the architecture to intel and silicon because there are two different types of computers and graphics cards.</figcaption></figure><p>Everything is enabled by default, even the Google and Android side.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c7ZbPJ620uJZl_fh00Lf4Q.png" /></figure><p>I typed in “XR Interaction toolkit”, and it was the same for me. I could add the Oculus and the Apple visionOS plugin and kit, but I decided not to because I do not own those devices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QWQVWDw78EHN-j7vLwsjJw.png" /></figure><p>By looking at the documentation on this package, it is updated to 3.1.1 and it seems very confusing because it has new features. If you look further, it will tell you which updates have been added in each version. From this document, it added the ability to easily jump and manipulate gravity in locomotion. Also, it added new improvements to add push and pull gestures with Vector 2 input controls for easier configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0sNnah4vCgvbwYuV5EVxzg.png" /></figure><p>We will look at the current gesture data for this toolkit version. This is the data that will allow to create objects, or interactables, without using any code.</p><p>For reference:</p><p>Interactors are the components that will apply the actions to each specified object. Interactables are the components that the interactors will apply the specified actions or gestures. (If this makes sense)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YGFi5oYs2okgBrbkqSWggA.png" /></figure><p>We are ready to make the first app.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52e61c4ef3c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use GitHub Desktop]]></title>
            <link>https://medium.com/@shanesmith822/how-to-use-github-desktop-201f6cc45249?source=rss-f082303a0527------2</link>
            <guid isPermaLink="false">https://medium.com/p/201f6cc45249</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <dc:creator><![CDATA[Shane Smith]]></dc:creator>
            <pubDate>Tue, 04 Mar 2025 09:04:26 GMT</pubDate>
            <atom:updated>2025-03-04T19:38:11.911Z</atom:updated>
            <content:encoded><![CDATA[<p>I will make a quick article on how to use the desktop version of GitHub.</p><p>First, download from this link:</p><p><a href="https://desktop.github.com/download/">Download GitHub Desktop</a></p><p>Then, when it is done installing, open up the desktop icon and it will look like this(If you make a desktop icon):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/68/1*38E2whjmW9fOc1VIKBgbtw.png" /></figure><p>It will have a display like this. I covered the current repository I have in red. I have Apple, so it is a little different for the external editor. (When it shows to open in XCode, but if it is Windows, it will show something different. It is the same with viewing the files, mine says ‘Finder’ but it is different for Windows or Linux.)</p><p>On the left side is where you will use most of the time and it has a lot of information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*___T3n8pH8oD6XEpJxRM7g.png" /></figure><p>It will highlight the current repository if you have more than one, or if you do not have one, there is a dropdown where it says add. (I used this project for school and I collaborated with more than one team.) It will list all repositories created from yourself, and the ones by the main collaborator.</p><p>The blue dots on the side, means that the repository has file changes. The down arrow, means that the repository needs to pull for changes. The up arrow means that the changes are needed to be pushed into the main branch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*MIm5xQzq6s21bSno0yvjqQ.png" /></figure><p>When you press ‘Add’, it will display a dropdown box where you can create a repository, clone one, or add one already downloaded.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*4r2PgsLBA8vORqwqhgdVow.png" /></figure><p>When you are signed in to your GitHub account, it will display all of your repositories and contributions (forks). It will also allow you to pick a path to clone the repository. (It is in my documents folder on my computer with its own folder.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*XsLrnKeuo6vrDGBsHjaFog.png" /></figure><p>If you work for an enterprise, it will allow you to log in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*lyd_hLlJ27fopGjRp8JxuA.png" /></figure><p>You can also use the URL given to you similar to the GitHub website and it will download from there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*lLYxlTphb1FQ36NSt9hmTg.png" /></figure><p>On the Create a New repository section, it is similar to when we created one from the GitHub website.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*gvMndt4lM_2FylujpR8PpA.png" /></figure><p>There is a slight warning on it, but ignore it because it is saying that it is a sub-folder of a repository. To explain, GitHub creates a parent directory and a sub-folder to manage necessary files. When GitHub desktop access the parent folder, it will recognize the sub-folder, but will not touch it. You don’t want all of your project information in one folder. (Thanks to this link: <a href="https://www.reddit.com/r/github/comments/xoupq2/github_desktop_not_reading_folders/?rdt=50231">https://www.reddit.com/r/github/comments/xoupq2/github_desktop_not_reading_folders/?rdt=50231</a>)</p><p>Adding a local repository, that path for your repository goes here, if you downloaded from the website (correct me if I am wrong.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*XSNLGTC3SGvFDHrwo_RRMQ.png" /></figure><p>Make changes and work on your project as usual. When you make the changes, you can add a commit (summary) with an optional description. You can press ‘Commit to Main’ and it will store your changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*9XZvD_1mV9MDC0DDG5f8WA.png" /></figure><p>Then it will ask you to push your changes.</p><p>If the repository needs to pull the origin, the third area will say ‘Pull Origin’ with a down arrow.</p><p>Press the ‘Push Origin’ button, and it will save your changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mGSb5ZFSYw52uzPQPu7Z8A.png" /></figure><p>That is it from me.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=201f6cc45249" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Blind GameDevHQ Game Jam Part 3.2]]></title>
            <link>https://medium.com/@shanesmith822/blind-gamedevhq-game-jam-part-3-2-89d97e0158f3?source=rss-f082303a0527------2</link>
            <guid isPermaLink="false">https://medium.com/p/89d97e0158f3</guid>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[gamedevhq]]></category>
            <dc:creator><![CDATA[Shane Smith]]></dc:creator>
            <pubDate>Mon, 03 Mar 2025 16:12:32 GMT</pubDate>
            <atom:updated>2025-03-04T06:38:44.624Z</atom:updated>
            <content:encoded><![CDATA[<p>Here is the other half, I divided into two, because the article was too long.</p><p>I have made a separate script with the sliders called UI_Slider.</p><pre>public class UI_Slider : MonoBehaviour<br>{<br>    [SerializeField] AudioMixer audioMix;<br>    float multiplier = 20;<br>    [SerializeField] Slider slider;</pre><pre>    float volumeScale;<br>  <br>   // public float ooo;<br>     [SerializeField] TMP_Text valueText;<br>    public string parameter;</pre><pre>    void Start()<br>    {<br>      // I will change this.<br>        slider.value = Mathf.Log(PlayerPrefs.GetFloat(parameter, 1)* multiplier) ;<br>        audioMix.SetFloat(parameter,Mathf.Log10(PlayerPrefs.GetFloat(parameter, 1)* 20));<br>    }</pre><pre>    public void SliderValue(float value)<br>    {<br>        volumeScale = value;<br>        valueText.text = $&quot;{Mathf.RoundToInt(value * 100) + &quot; %&quot;}&quot;;</pre><pre>        // logrithmic value.<br>        audioMix.SetFloat(parameter, Mathf.Log10(value) * multiplier);</pre><pre>        //SaveValues(value);<br>    }</pre><pre>    public void SaveValues(float value)<br>    {<br>        volumeScale = value;<br>        PlayerPrefs.SetFloat(parameter, value); // using the exposed strings of the mixer<br>        PlayerPrefs.Save();<br>    }</pre><pre>    public float VolumeScale()<br>    {<br>        return volumeScale;<br>    }</pre><pre>}</pre><p>For this, I made some values that that will be used here. I made a value for the AudioMixer, named audioMix, the Slider, named slider, the TMP_Text, named valueText, and the string named parameter. I made two private floats, named volumeScale, and multiplier.</p><p>I will explain this as much as I can. The AudioMixer has a minimum value of -80 decibels and a maximum of 20 decibels. What we want is to make the numbers between -80 and 0. We can do this a lot of ways, but it is better to do a logarithmic calculation because we perceive audio in a non-linear way, similar to a logarithmic calculation. You can hear the difference when you increase and decrease the volume. I looked at two tutorials, but one was from Llam Academy and here is a deeper explanation from a Wikipedia article: <a href="https://en.wikipedia.org/wiki/Decibel#Uses">https://en.wikipedia.org/wiki/Decibel#Uses</a></p><p>I will explain how Logs work in math. A Log in math takes a base number and value and calculates how many times can the base number can multiply by itself to reach a value. For example, Log4(64) = 3. A value of 64 and a base of 4 will equal 3. If you multiply the number 4 by itself 3 times, it will equal 64, or 4 * 4* 4. On a smart calculator, you enter the value first, press the log button, and then enter the base number. They are sometimes called the inverse of exponents. Here is a better explanation from this link: <a href="https://www.britannica.com/science/logarithm">https://www.britannica.com/science/logarithm</a></p><p>Note:(Logs do not support zeros)</p><p>We will be using Log10 as the MathF. calculation to use.</p><p>For the ‘SliderValue()’ function, I made the personal float volumeScale equal to the local variable named, ‘value’. I made the valueText text equal to the MathF.RoundToInt calculation as the local variable, ‘value’ and multiplied it by 100, concatenated with a percentage. I wanted the value to be converted into a percentage. For the audioMixer, we use the SetFloat() method, which requires a string and a float. We used the public ‘parameter’ string, and the ‘value’ variable and multiplied by the ‘multiplier’ float value which equals 20. This calculation is recommended by the link that was provided about decibels. From this calculation, if we set the value to 1, then the result multiplied by 20 will equal zero. Log10(1) or a value of one with no base will equal zero, multiply it by 20 and it will equal zero. This is the same value on the audioMixer scale, which we do not want it louder.</p><p>For the ‘SaveValues()’ function, I made the personal float volumeScale equal to the local variable again. Using PlayerPrefs, which is a UnityClass that stores floats, strings, and integers in between game sessions, we create a key from the public string, and the ‘value’ variable. We have to use the PlayerPrefs.Save() , in order to make the data persist in the game session.</p><p>I made a public float named VolumeScale and made the void to return the private ‘volumeScale’ variable.</p><p>For the Start() function, this was a little tricky. First, I made the slider.value equal to a Mathf.Log function that gets the saved value from PlayerPrefs and multiplies it by 20. The GetFloat() from PlayerPrefs will gather the saved variables, such as the string name and the default float value. The max value for the sliders is one. and I think it works because with the active calculations, the slider value and the set float values are more than one. The values equal 2.7-ish for the slider value and 1.3-ish for the mixer. respectively. It works.</p><p>Note: The start function should have started with a Mathf.Log10 on the audioMix variable instead of Mathf.Log. If you do not specify a base in the Log function, it will automatically assume the base as 2.7183, which is the natural base of e in a function. Edited to add this:</p><pre>void Start()<br>{<br>  slider.value = Mathf.Log10(10) ;<br>  audioMix.SetFloat(parameter,PlayerPrefs.GetFloat(parameter, 0)); // make sure that any value equals zero<br>}</pre><p>The log10 calculation for the value of ten is 1. I set the default value from GetFloat() to zero with no log calculation. It works perfectly and it has exact values.</p><p>The problem was that the values for the mixer moved to 1 instead of zero. While that is nice, we want exact values here.</p><p>Set the values in the inspector.</p><p>Here is the MenuManager:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*753foCAlZWHIoT3iOx1PwQ.png" /></figure><p>Here is all of the values for the options Menu:</p><p>Back Button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*xk0-Oqt2zQZTfj8ahJwSRg.png" /></figure><p>CloseWindow( it is the same for the pause menu and options menu):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*z4GMSANFNNqyxdTcH9OgYQ.png" /></figure><p>Save Button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*pxBg-loyYn7RGmkiI4lvYw.png" /></figure><p>Background Music Slider:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/1*8t9bCf333MOv0YV9LWKcvg.png" /></figure><p>By making a script for the sliders, we made the values dynamic when we applied it to the ‘On Value Changed’ event.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*UKPdn-5_T93ARzEWRd_39Q.png" /></figure><p>Sound Effects Slider:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/328/1*4M0A7DhdlbRgZPdrrZOb8g.png" /></figure><p>It is the same for here. We made the slider value, which takes a float, dynamic. It means that it can be manipulated in run time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*wfRu8Q9SSKQEt4Gnh0mPDg.png" /></figure><p>Here are the value of the min and max values of the sliders:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*cA4f9DEY5Qn7C5bmIDwmUw.png" /></figure><p>They are this way because we can be able to lower the values in relation to the decibels in the audio mixer. (This will be shown later).</p><p>Let’s set all the values for the Pause Menu:</p><p>The Options Button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*vfCbdbjhFSg2hb0JzbKCRQ.png" /></figure><p>Main Menu: Modified for later, It has nothing right now.</p><p>The Close Button:</p><p>It has the same function as the close window portion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*utYes-_O8LzlDUfDNYzkGg.png" /></figure><p>I have done some small changes to the scripts.</p><p>For the audioManager:</p><p>This has the same function as StopAllBG(), which will stop every song that is in the SFX array.</p><pre>public void StopAllSFX() // other <br>    {<br>        for (int i = 0; i &lt; sfx.Length; i++)<br>        {<br>              sfx[i].Stop();<br>        }<br>    }</pre><p>For the gun:</p><pre>[SerializeField] float fireRate;</pre><pre>    private float _timePassed;</pre><pre>private void Fire_performed(UnityEngine.InputSystem.InputAction.CallbackContext obj)<br>    {<br>        if (Time.time &gt; _timePassed)<br>        { FireGun(); }<br>    }<br>private void FireGun()<br>    {<br>        // no spamming the fire button/ this is also for audio<br>        _timePassed = Time.time + fireRate;<br>       <br>    }</pre><p>I added a function to make a firing delay, similar to what we have done in the Space Shooter. I added a float called fireRate, and a private float called _timePassed. If certain time has passed, then we will fire.The value for _timePassed is equal to Time.time + fireRate.</p><p>Result: (UI only)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mCqVse6pHeI_1GP8LdgKQQ.gif" /></figure><p>It all works!</p><p>On the bottom, it confirmed the value of the sliders when I used a debug log.</p><p>Note: The values jumped to one on the mixer when I pressed the options button. I added an edit on the code. The slider should reflect 1 on the slider and zero on the mixer.</p><p>Even the delay works.</p><p>Note:(Some of the code you see for the Gun, Controls, and Weapon types, are all of the changes that have I made. The full scripts I have created are the Singleton, AudioManager, UI_Slider, and Menu Manager. )</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89d97e0158f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Blind GameDevHQ Game Jam Part 3.1:]]></title>
            <link>https://medium.com/@shanesmith822/blind-gamedevhq-game-jam-part-3-22a0417ed534?source=rss-f082303a0527------2</link>
            <guid isPermaLink="false">https://medium.com/p/22a0417ed534</guid>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[gamedevhq]]></category>
            <dc:creator><![CDATA[Shane Smith]]></dc:creator>
            <pubDate>Mon, 03 Mar 2025 07:53:06 GMT</pubDate>
            <atom:updated>2025-03-03T16:10:56.620Z</atom:updated>
            <content:encoded><![CDATA[<p>I need to make a menu for the sound because the sounds are ear-splitting.</p><p>Note: This is an in-depth audio article, I have a basic one for a pause menu and a settings menu.</p><p>First, let’s create an audio mixer.</p><p>Here is the menu to access the audio mixer:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*3J0X25Tc81Pj12LR7nntuw.png" /></figure><p>Then, press the plus sign to create the mixer. After this, go into the groups section and press the plus sign twice to create one for sound effects and one for back ground music.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*haYpimbLrQ8qe4Vq1Wh0SA.png" /></figure><p>We need to expose the paramenters like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SMf3ZAfIkJu18ixVH0p7hw.png" /></figure><p>We can right click on the area of the exposed parameters and we can rename it. I named it SFX, of course.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*mpTfsXQ4ahAPyOmt-N7lgw.png" /></figure><p>We can repeat this for the BGM group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iTZd3CngkfbcINm_Pf_cQA.png" /></figure><p>I named this parameter for the BGM group, BGM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*WQ00pDsxEcOUpaSI4Eup6Q.png" /></figure><p>We can also do it for the master volume, but it is optional.</p><p>Let’s create some UI controls for the inputs.</p><p>From the input controls, I added an action map for UI and two actions. One is for canceling, and one for pausing. I made the escape button on the keyboard for the cancel input, and the P key for pausing. more can be added later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*POhNg5bcelJfhEe8dgc22g.png" /></figure><p>Then, we need to make a basic panel for a pause script and options script:</p><p>This is a rough options menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*pRl8NObQvEDm7JBDmNVMZA.png" /><figcaption>The button on the bottom can be used for later. The box at the top is used for closing the menu with a mouse.</figcaption></figure><p>This is the pause menu:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*SOSpyGbSJtjIvCH1jnxzZg.png" /><figcaption>The box at the end is used to close the window when it is clicked on with a mouse.</figcaption></figure><p>Create a script for this. I named it MenuManager.</p><pre>public class MenuManager : Singleton&lt;MenuManager&gt;<br>{<br>    /// &lt;summary&gt;<br>    /// This script can be combined with the UIManager or its own seperate one.<br>    /// This script can also be deleted.<br>    /// &lt;/summary&gt;<br>      TankControlInputs _tankControlInputs;<br><br>    [Header(&quot;Options Menu&quot;)]<br>    [SerializeField] GameObject optionsPanel;<br><br>    public UI_Slider[] Sliders;<br>    [SerializeField] Button back;<br>    [SerializeField] Button save;<br><br><br>    [Header(&quot;Pause Menu&quot;)]<br>    [SerializeField] bool isPaused;<br>    [SerializeField] Button cancel;<br>    [SerializeField] Button options;<br>    [SerializeField] Button mainMenu;<br><br>    //float currentValue = 1;<br>    [SerializeField] GameObject menuPanel;<br><br>    bool isMenuOpen; /// this can be deleted.<br>    <br>    // Start is called before the first frame update<br>    void Start()<br>    {<br>        _tankControlInputs = new();<br>        _tankControlInputs.UI.Enable();<br><br>        _tankControlInputs.UI.Cancel.performed += CloseMenu_Performed;<br>        _tankControlInputs.UI.Pause.performed += PauseMenuOpened;<br>    }<br><br>    private void PauseMenuOpened(InputAction.CallbackContext context)<br>    {<br>        OpenMenu();<br>    }<br><br>    private void CloseMenu_Performed(InputAction.CallbackContext context)<br>    {<br>       CloseMenu();<br>    }<br><br>    // Update is called once per frame<br>    void Update()<br>    { <br>/// do not have to use time scale, we can make the object to stop moving with a method<br><br>        if (isPaused)<br>        {<br>            // add any other function<br>            Time.timeScale = 0f;<br>        }<br>        else<br>        {<br>            // add any other function<br>            Time.timeScale = 1f;<br>        }<br><br>        if(isMenuOpen)<br>        {<br>            // this can be used on the pause bool<br>        AudioManager.Instance.StopAllBG();<br>        AudioManager.Instance.StopAllSFX();<br>        }<br>    }<br><br>    public void OpenMenu() // pause menu<br>    {<br>        isMenuOpen = true;<br>        menuPanel.SetActive(true);<br>        isPaused = true;<br>       // AudioManager.Instance.StopAllBG();<br>       // AudioManager.Instance.StopAllSFX();<br>        <br>    }<br><br>    public void CloseMenu() //  the button on the right corner of the window<br>    {<br>        isMenuOpen = false;<br>        menuPanel.SetActive(false);<br>        optionsPanel.SetActive(false);<br>        isPaused = false;<br><br>    }<br>    #region Options Menu<br><br>    public void BackButton() // for options menu only<br>    {<br>      isMenuOpen = true;<br>        isPaused = true;<br>        optionsPanel.SetActive(false);<br>        menuPanel.SetActive(true);<br>    }<br><br>    public void OpenOptionsMenu() // for options menu only<br>    {<br>        isMenuOpen = true;<br>        isPaused = true;<br>        menuPanel.SetActive(false);<br>        optionsPanel.SetActive(true);<br>    }<br><br>   <br>   public void SaveButton()<br>   {<br>    for  (int i  = 0; i &lt; Sliders.Length; i++)<br>    {<br>       float currentValue = Sliders[i].VolumeScale();<br>        <br>       Sliders[i].SaveValues(currentValue);<br>        //Debug.Log(currentValue);<br>    }<br>   }<br>    #endregion<br>    <br>}</pre><p>I will explain the script.</p><p>On the top, I added the TankControlInputs because of the UI action maps and inputs created earlier. The headers divide the variables into categories.</p><p>For the pause menu, I added three buttons, two bools (one can suffice here), and the panel. The buttons are the Options menu, Main menu and Close. The Main menu one does nothing for now. The bools are named isPaused, and isMenuOpen.</p><p>For the options menu, I made two buttons, a gameObject for the panel, and the UI Sliders array, which the script is shown a little later. The buttons are the back and the save button.</p><p>For the start function, I enabled the inputs and added the ability to perform pausing and closing.</p><p>In the Update function, if the isPaused bool is true, then the timeScale is equal to 0. In reverse, the time scale will equal to 1. If the isMenuOpen is true, then we stop the music using the the methods from the audioManager. It is StopAllBG(), and StopAllSFX(), which is the same as StopAllBG(), but we are stopping the sound effects instead.</p><p>For the ‘ Open Menu’ method, we set the menuPanel to true, the isPaused bool to true, and the isMenuOpened to true.</p><p>The ‘CloseMenu()’ function will set the menuPanel and theoptionPanel to false. Both of the bools are also set to false.</p><p>In the Options section, We have the Back Button(), SaveButton(), and an OpenOptions() method.</p><p>For the BackButton() method, it will close the optionsPanel, but keep everything else active and true.</p><p>For the ‘OpenOptionsMenu()’ method, it will close the menuPanel, but keep everything else active and true.</p><p>For the ‘SaveButton()’ method, for every UI_Slider we have, we will save the values from the sliders from the UI_Slider script. I made a local float value called currentValue and it is equal to the float method VolumeScale(). Do not forget to comment out the Debug.Log.</p><p>I will make a separate article on the other half.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22a0417ed534" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>