Projectile for top down 2d receiving new direction per update (Not what I want)

Hello! I’m incredibly new to c# and unity in general so forgive my ignorance! I’ve been messing around with rpg things and recently have been wanting to make my lil dude shoot projectiles! (similar to a game call rotmg where they go out a certain distance from the player at the direction of the mouse and disappear unless collision is detected!)
I attached a script to my player for instantiating my projectile (deals with spawn point and rotation) and then made a prefab of the bullet sprite with rigidbody2d, a boxcollider, and a super simple bulletmove script!

BulletInstantiateScript:

public GameObject bullet;
public float speed;

//private Rigidbody2D myRigidBody;

// Use this for initialization
void Start()
{
    //myRigidBody = GetComponent<Rigidbody2D>();
}

void Update()
{
    if (Input.GetMouseButtonDown(0))
    {
        Vector2 target = Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y));
        Vector2 myPos = new Vector2(transform.position.x, transform.position.y);
        Vector2 direction = target - myPos;
        direction.Normalize();
        Quaternion rotation = Quaternion.Euler(0, 0, Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg + -90f);
        GameObject projectile = (GameObject)Instantiate(bullet, myPos, rotation);
        GetComponent<Rigidbody2D>().velocity = direction * speed;
        //myRigidBody.velocity = direction * speed;
        
    }
}

and the bulletMoveScript:

public float timeToDestroy;

public float amount;
private Rigidbody2D myRigidBody;

void Start()
{
    myRigidBody = GetComponent<Rigidbody2D>();

}

// Use this for initialization
void Update()
{

        if (Input.GetKey(KeyCode.Mouse0))
        {
            Vector3 sp = Camera.main.WorldToScreenPoint(transform.position);
            Vector3 direction = (Input.mousePosition - sp).normalized;
            //myRigidBody.AddForce(direction * amount);
            myRigidBody.velocity = direction * amount;
        }

        //here forward is the destroy over time script  bc idk how to do distance yet
        timeToDestroy -= Time.deltaTime;
        if (timeToDestroy <= 0)
        {
            Destroy(gameObject);
        }

}

private void OnTriggerEnter2D(Collider2D other)
{
    if (other.gameObject.tag == "Enemy")
    {
        Destroy(this.gameObject);
    }

    if (other.gameObject.tag == "collider")
    {
        Destroy(this.gameObject);
    }
         
}

the original bulletinstantiate script was supposed to move the bullet by itself (hence the extra lines of code in there) but I couldn’t figure out how to do that!

The problem I’m having is that in this way I can create the projectile when I fire, its rotation is correct, and the initial direction is correct, but if I fire again, the projectile(s depending on if there are multiple) changes direction towards where I just clicked! I have scoured the internet for 7 ish hours now and have messed around with the code for an equal amount of time all to no avail! Idk what I’m doing but apparently I need some help! How do I make it so that each projectile spawn has a set direction (dictated by the mouse position at time of firing) that will not vary if I continue to shoot? (I would like to have it continue to shoot projectiles as long as the fire button is held down and have each new spawn of projectile aimed toward wherever the mouse is at time of spawn but that seems as simple as changing getkeydown to getkey and then adding a cooldown to the firing! I’m not quite sure though!)
Thanks for your help!
(P.s. I know my code is really messy but I just started about two weeks ago with c# so just bear with me!)

Ok, problem solved no thanks to anyone but myself! Basically I just added a bool that activated if it was moving in the update function so the update function looks like this:

    if (Input.GetKey(KeyCode.Mouse0))
    {
        if (!isMoving)
        {
            Vector3 sp = Camera.main.WorldToScreenPoint(transform.position);
            Vector3 direction = (Input.mousePosition - sp).normalized;
            myRigidBody.velocity = direction * amount;

            //problem solver bool right here
            isMoving = true;
        } 
    }

making it not change the direction every time i clicked! The other problem was solved simply by adding a countdown timer of sorts to it! the script below is a work in progress bc I’m trying to add a dexterity function but how I’m doing it isn’t working well due to not being able to add decimals to an int… I’ll get it eventually and post it if there is a demand though! Heres the firerate script finalized though!

//script start

public GameObject bullet;

public float attackTime;
public float attackTimeCounter;

//for dex capabilities added in later, currently gatta convert int array to float to get my leveling system working. tough stuff
//public float shootSpeed;

public bool attacking;

// Use this for initialization
void Start()
{

}

void Update()
{

    if (!attacking)
    {
        if (Input.GetMouseButton(0))
        {

            attacking = true;
            //attackTimeCounter = attackTime - shootSpeed;

            Vector2 target = Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y));
            Vector2 myPos = new Vector2(transform.position.x, transform.position.y);
            Vector2 direction = target - myPos;
            direction.Normalize();
            Quaternion rotation = Quaternion.Euler(0, 0, Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg + -90f);
            GameObject projectile = (GameObject)Instantiate(bullet, myPos, rotation);
        }

    }

    if (attackTimeCounter >= 0)
    {
        attackTimeCounter -= Time.deltaTime;
    }

    if (attackTimeCounter < 0)
    {
        attacking = false;
    }

}

the last problem i’m getting is: “Assets/Scripts/BulletTest.cs(39,28): warning CS0219: The variable `projectile’ is assigned but its value is never used” And I’m not entirely sure why that is but I’ll keep working on it! Thanks for all my help!