Why is a transform variable only assigned in Start() changing frame-by-frame?

This is for a 2D project. I have a gameobject for a missile prefab, and in the script for it I declared two privates, one gameobject ( the crosshairs ) and one transform (the target location upon clicking), and in start I find the crosshair object to ch, and assign its transform to target t, with the goal of using this t.position as a fixed point that a missile will be fired at. HOWEVER, somehow as I move the mouse after that, the t.position keeps changing to the current crosshair ch position, and that’s definitely not the goal lol. If somebody could help me pinpoint the issue, that’d be awesome. Below I’ll post screenshots of the code and logs. The cursor_position and mouse_position logs are from a separate script keeping track of where the cursor is.

201013-code-stuff.jpg

alt text

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

public class tracker : MonoBehaviour
{
    private GameObject ch;
    private Transform t;
    private int timer = 0;
    // Start is called before the first frame update
    void Start()
    {
        ch = GameObject.Find("crosshair");
        Debug.Log("crosshair position: " + ch.transform.position);
        t = ch.transform;
        timer = 0;
    }

    // Update is called once per frame
    void Update()
    {
        if(timer == 0)
        {
            Debug.Log("timer = " + timer);
            Debug.Log("starter t: " + t.position + "

starter ch.position: " + ch.transform.position);
}
//Timer is for printing out the message every 5 seconds, also happens //almost immediately…
if(timer <= 5000)
{
timer++;
if(timer == 5000)
{
Debug.Log("t: " + t.position + "
ch: " + ch.transform.position);
if(t.position == ch.transform.position)
{
Debug.Log(“busted…”);
timer = 5001;
}
}
}
}
}
/* START OF CROSSHAIR_CONTROL SCRIPT */
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

       public class crosshair_control : MonoBehaviour
       {
        int timer = 0;
        // Start is called before the first frame update
        void Start()
        {
            Cursor.visible = false;
        }
    
        // Update is called once per frame
        void Update()
        {
            Vector2 mouse_cursor_position = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            transform.position = mouse_cursor_position;
            timer++;
            if(timer == 2000)
            {
                Debug.Log("cursor position: " + transform.position +"

mouse_cursor_position: " + mouse_cursor_position);
timer = 0;
}

        }
    }

I believe t.position keeps on changing to be the crosshair position because you set t to be a reference to the crosshair transform in Start(). → t = ch.transform;

Then every time t.position is called, you are basically still calling the ch.transform.position.
Try instead of t = ch.transform, use t = ch.transform.position and then replace the rest of your t.positions with t. Hope this helps.