Move GameObject to Position, Waiting, and then Moving to Another Position

Greetings,
I have been playing around with WaitForSeconds and I can’t seem to get this right.
The script I’m trying to create is for a simple simulation game. This particular script is for a customer. The outcome I am trying to get is for an object to go to a certain object, stop and wait for 30 seconds and then go to another position. Right now the object does not move at all. Could I get some pointers about where I’m going wrong. Perhaps there is a better solution for what I am trying to achieve?

{
public Transform target;
public Transform target2;
public float speed;

void Start()
{
    float step = speed * Time.deltaTime;
    transform.position = Vector3.MoveTowards(transform.position, target.position, step);
    StartCoroutine(WaitAndGo());
}

IEnumerator WaitAndGo()
{
    yield return new WaitForSeconds(30);
    float step = speed * Time.deltaTime;
    transform.position = Vector3.MoveTowards(transform.position, target2.position, step);
}

}

You have nothing indicating when the transform has arrived and so the movement functions are only moving for single frames. It will move for a single frame when Start() is called, starts the coroutine, wait for 30 seconds, them take another step towards target2.position. The Vector3.MoveTowards needs to be in Update() or a looped Coroutine for it to be run every frame, and you’ll need to add in a way to detect whether the transform has arrived so that it knows when to stop Vector3.MoveTowards.

Okay, this is great! But I am running into an error that says "Argument 1: Cannot Convert from 'unityEngine.Transform to “UnityEngine Vector 3”

You’ll have to bear with me for I am very new and am still looking over the Scripting API. This is like taking a foreign language haha.
Thank you for your time and patience thus far.

Looking at your latest attempt, I notice you are trying to verify if a float distance equals to 0. That has a lot of chances for failing. It may be that the number never gets to a perfect 0 (could end up 0.011111, etc), so the loop never ends. This is the kind of place where you would put a debug.log inside the loop to verify if it’s still running, and if needed find a better condition for exiting the loop (you could compare if both transform.positions are the same or you could check if the current value is less than <0.1f instead). Now the second movement is just wrong anyways. If you are planning to have the same kind of operation it stands to reason that you’d need another while loop for moving the second time (just like the first one), just an if conditional won’t do. As it is now, the system will wait 5f seconds then move the object a tiny, tiny bit and the coroutine will finalize, stopping forever.

Did you try: this.gameobject.transform.position?

Hello, Similar Isue, i have a code to change GameObject.transform.position to another position after counting. The isue is when I run the code, it changes the position first even when the WaitForSeconds() is before it.

here is the code of my IEnumerator():

IEnumerator MyCoroutine(){
        yield return new WaitForSeconds(5);
	transform.position = Other.position;
}