Accessing a variable from another script on the same object? C#

Hello again.
For my game I am trying to get my clickToMove script to access my targeting script so instead of when you right click an enemy and it targets and then continues to walk to the location that you click, instead it takes the target from the other script and walks in front of the target instead. The problem is I don’t know how to access the variable on the other script.

The game component is a sprite.

I have checked quite a few different answers but none of them seem to work or apply to what I’m trying to do.

Here is the target select bit:

private Transform selectedTarget = null;

void Update(){
	if (Input.GetMouseButtonDown(1)){ // when button clicked...
		Vector3 pos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
		//Debug.Log (pos);
		RaycastHit2D hit; // cast a ray from mouse pointer:
		hit = Physics2D.Raycast (pos,;
		if (hit != null && hit.transform != null && hit.transform.CompareTag("Enemy")) {
			DeselectTarget(); // deselect previous target (if any)...
			selectedTarget = hit.transform; // set the new one...
			SelectTarget(); // and select it

You look at one of your other scripts the same way you look at a script on someone else, using getComponent. is the official reference man page. Sundar (comment above) has an example in SelectTarget.

Since the place to look is “you,” you can just write GetComponent with nothing in front of it. Or transform.Get... or gameObject.Get... if you prefer the “never leave it blank” style.