Any advice to improve script

So let me preface by saying I am brand new to Unity and I have no coding background. Currently I going through the Junior Programmer pathway on Unity Learn and for a personal project I attempting to remake the Fly Swatter game from Mario Paint. I have managed to script what I can to mimic the movement characteristics of some of the bug enemies. I have provided a clip of the yellow bugs from the original game and a clip from what I have come up with which are the red squares in the clip. Personally just wanted get some professional opinions on how I could do this in alternative ways or more efficiently. I have attached my scripts that I have made. Thanks in advance sorry if I have violated any rules I rarely post on any forums.
peacefulinnocentboa
jaggedslighteel

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class bugType2 : MonoBehaviour
{

    private Vector3 targetPosition;
    public float travelToThisPosition = 20;
    public float speed = 15;
    public int frameCounter = 0;
    public int timeToLive = 1200;
    private int positionNumber;

    // Start is called before the first frame update
    void Start()
    {
        // CheckStartingPosition is called once at the beginning of objects life to verify
        // starting position and set the correct value for positionNumber variable
        CheckStartingPosition();

    }

    // Update is called once per frame
    void Update()
    {
        // Here we are correlating the value of positionNumber to determine where starting position is
        // based on that a function is called every frame to move in the correct direction
        if (positionNumber == 1)
        {

            Debug.Log("This should move right");
            MoveRight();

        }
        else if (positionNumber == 2)
        {

            Debug.Log("This should move down");
            MoveDown();

        }
        else if (positionNumber == 3)
        {

            Debug.Log("This should move left");
            MoveLeft();

        }
        else if (positionNumber == 4)

        {
            Debug.Log("This should move up");
            MoveUp();

        }

    }

    // At the end of a frame the UpdateFrameCounter function is called to update frame counter
    private void LateUpdate()
    {

        UpdateFrameCounter();

    }

    // This function adds to the frame counter until it reaches a specified amount then destroys object
    void UpdateFrameCounter()
    {

        if (frameCounter < timeToLive)
        {
            frameCounter++;
        }
        else
        {
            Destroy(gameObject);
        }

    }

    // This function checks the position on the specified axis to determine where the starting position is
    void CheckStartingPosition()
    {

        if (transform.position.x <= -26)
        {
            Debug.Log("Move right");
            MoveRight();
            positionNumber = 1;
        }
        else if (transform.position.z >= 26)
        {
            Debug.Log("Move down");
            MoveDown();
            positionNumber = 2;
        }
        else if (transform.position.x >= 26)
        {
            Debug.Log("Move left");
            MoveLeft();
            positionNumber = 3;
        }
        else if (transform.position.z <= -26)
        {
            Debug.Log("Move up");
            MoveUp();
            positionNumber = 4;
        }

    }

    // This function moves object right
    void MoveRight()
    {
        targetPosition = new Vector3(-travelToThisPosition, transform.position.y, transform.position.z);

        transform.position = Vector3.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);
    }

    // This function moves object down
    void MoveDown()
    {
        targetPosition = new Vector3(transform.position.x, transform.position.y, travelToThisPosition);

        transform.position = Vector3.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);
    }

    // This function moves object left
    void MoveLeft()
    {
        targetPosition = new Vector3(travelToThisPosition, transform.position.y, transform.position.z);

        transform.position = Vector3.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);
    }

    // This function moves object up
    void MoveUp()
    {
        targetPosition = new Vector3(transform.position.x, transform.position.y, -travelToThisPosition);

        transform.position = Vector3.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);
    }


}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpawnManager : MonoBehaviour
{

    private float spawnRange = 20.0f;
    public GameObject bugTypeSelection1;
    public GameObject bugTypeSelection2;
    public Vector3[] SpawnPos;
    private int spawnTotal;
    public int frameCounter = 0;

    // Update is called once per frame
    void Update()
    {

        int spawnIndex = Random.Range(0, 4);
        spawnTotal = 4;
        SpawnPos = new Vector3[spawnTotal];
       

        SpawnPos[0] = new Vector3(-26, 0, Random.Range(-spawnRange, spawnRange));
       
        SpawnPos[1] = new Vector3(Random.Range(-spawnRange, spawnRange), 0, 26);
       
        SpawnPos[2] = new Vector3(26, 0, Random.Range(-spawnRange, spawnRange));
      
        SpawnPos[3] = new Vector3(Random.Range(-spawnRange, spawnRange), 0, -26);


      

       

        if (Input.GetKeyDown(KeyCode.Space))
        {

            Instantiate(bugTypeSelection1, SpawnPos[spawnIndex], bugTypeSelection1.transform.rotation);

        }

    }

    private void LateUpdate()
    {


        if (frameCounter < 1000)
        {
            frameCounter++;
        }
        else
        {
            Instantiate(bugTypeSelection2, new Vector3(0, 0, 0), bugTypeSelection2.transform.rotation);
            frameCounter = frameCounter - 1000;
        }


    }

}

Looks good to me… nice and straight and simple.

The more important question is… Do you understand all parts of it?

I suggest you pick this up again 7 days from now and go through all of it and explain every single line to your dog (see how I’m doing that). You’ll be surprised at how much will have faded in a week!

How to do tutorials properly, two (2) simple steps to success:

Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That’s how software engineering works. Every step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.

Fortunately this is the easiest part to get right: Be a robot. Don’t make any mistakes.
BE PERFECT IN EVERYTHING YOU DO HERE!!

If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.
Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.

Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there’s an error, you will NEVER be the first guy to find it.

Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!

Thanks a bunch, reading your advice really resonated with me as I have been trying to be aware of “Am I actually learning? Am I retaining anything?” and using comments in my script is really helping as it forces me summarize what stuff does and later helps me to understand what I did. Yea I never wanted to copy and paste any code that someone else wrote because I didn’t put forth the mental power to write it therefore I don’t understand it. Later after I have a prototype working I will add some quality assets but if I wanted to transition from a 3D to 2D or 2.5D game would the transition be a simple as removing one of the axis i.e. Vector3 to Vector2?

I like your thinking but no… alas, it’s not quite that simple. Plus what people mean when they say 2D or 2.5D or 3D is quite varied, especially 2.5D… there’s a LOT of interpretations of that.

If you want to see one possible interpretation of it, check out my silly little demo:

https://www.youtube.com/watch?v=BtT1N1lzFns

If you want a real challenge, dig through the source and see if you can figure out what each part does!

Come back and ask specific questions if you get utterly lost.

Full source here:

proximity_buttons is presently hosted at these locations:

https://bitbucket.org/kurtdekker/proximity_buttons