How to allow movement of game object to certain points only

Hey guys, I am new to Unity and I am building a 2D game. The purpose of the following two scripts is to check if and only if the user clicks on a node (specific clickable points on the screen), a “bat” should spawn at a given location and move to the node’s location. I attempted this through using a script (MoveTo, attached to node) which contains a boolean that is set to true upon being clicked, and instantiates the bat at a given at 0,0,0. After doing that, the node is deleted. The other class, BatMoveC (attached to the bat) will then check if the boolean is set to true and rotate and animate the bat to that location. Unfortunately, this isnt working. I this the best way to do this? Do you recommend another method or is it fixable and I’m just being a noob :stuck_out_tongue:

Here is MoveTo:

using UnityEngine;
using System.Collections;

public class MoveTo : MonoBehaviour {

	public GameObject Bat;
	public bool move;

	// Use this for initialization
	void Start () {
		move = false;
	}

	
	// Update is called once per frame
	void Update () {
	}
	void OnMouseDown()
	{
		Instantiate (Bat, new Vector3 (0, 0, 0), Quaternion.identity);
		move = true;		
		Destroy (this.gameObject);
	}

}

Here is the BatMoveC script:

using UnityEngine;
using System.Collections;

public class BatMoveC : MonoBehaviour {

	public float speed = 10f;
	public float rotationSpeed = 5000f;
	private Quaternion qTo;
	private Vector3 pos;
	private bool moveable;

	// Use this for initialization
	void Start () {
		pos = transform.position;
		qTo = transform.rotation;
		moveable = false;
	}

	
	// Update is called once per frame
	void Update () {
		GameObject go = GameObject.Find ("MoveTo");
		MoveTo moveTo = GetComponent<MoveTo> ();
		moveable = moveTo.move;
		if (moveable){
						
								pos = Input.mousePosition;
								pos.z = transform.position.z - Camera.main.transform.position.z;
								pos = Camera.main.ScreenToWorldPoint (pos);
						
						Vector3 dir = pos - transform.position;
		
						if (dir != Vector3.zero) {
								qTo = Quaternion.FromToRotation (transform.right, dir) * transform.rotation;
								transform.rotation = Quaternion.RotateTowards (transform.rotation, qTo, Time.deltaTime * rotationSpeed);
						}
						transform.position = Vector3.MoveTowards (transform.position, pos, Time.deltaTime * speed);
				}
	}
}

Thanks a million for your help <3

public class MoveTo : MonoBehaviour {

public GameObject Bat;
 
  void OnMouseDown()
  {
    GameObject myBat = Instantiate (Bat, new Vector3 (0, 0, 0), Quaternion.identity);
    myBat.GetComponent<BatMoveC>().target = transform.position;
    Destroy (gameObject);
  }
 
}

public class BatMoveC : MonoBehaviour {
 
public Vector3 target = Vector3.Zero;     
 
void Update () {
  if (target != Vector3.Zero){
    //Move to target
  }
}

Try these. There maybe some spelling mistakes but I guess the logic works.