Accessing Vector3 variable from another script and having the object move towards that location

Hi, in ScriptA I have

animal.GetComponent<Patrol>().**target2** = new Vector3(transform.position.x, 3.580481f, transform.position.z);

The animal Object that contains ScriptB calls this

transform.position = Vector3.MoveTowards(transform.position, **target2**.transform.position, Time.deltaTime);

I get the following error:
Type ‘UnityEngine.Vector3’ does not contain a definition for ‘transform’ and no extension method transform of type ‘UnityEngine.Vetor3’ could be found. . .

What am I doing wrong??

target2 is a Vector3, not a transform. you are trying to access the position variable of a Vector3 which doesn’t exist. A Vector3 only has the variables outlined in the last link posted below.

A transforms position variable is a Vector3. You already have a Vector3 (target2) so just use that :

transform.position = Vector3.MoveTowards(transform.position, target2, Time.deltaTime);