Move towards not working with velocity in script

I have a player with rigidbody set to dynamic. The player jumps on platforms. At some certain time I want the player to move towards a gameobject using Vector3.MoveTowards. But the script doesn’t work and gives a object not set to reference error.

Here’s the script.

Transform ReviverBox;

Rigidbody2D rb;

void Start () {
        ReviverBox = GameObject.FindWithTag("Reviver").transform;
}

void Update () {

      if (GameManager.instance.reviveBool)
       {

            transform.position = Vector3.MoveTowards(transform.position, ReviverBox.position, ReviveSpeed * Time.deltaTime);    // this line gives the error.
       }

            movement = Input.GetAxis("Horizontal") * speed;
}


void FixedUpdate(){
		Vector2 velocity = rb.velocity;
		velocity.x = movement;
		rb.velocity = velocity;
	
	
	}

Debug the code.

What reference is missing? The ReviverBox? IF you have “object not set to reference error” most probably is not “Vector3.MoveTowards” problem, is a reference problem.

First, do as tutorail shows, create a float variable to calculate the step before using MoveTowards, and use this 2 debug.log before MoveTowards to check via console if everything is ok.

Debug.Log (ReviverBox.position);
Debug.Log (ReviveSpeed);

“object not set to reference error” can be caused by incorrect initialization of ReviverBox. You can simply
define ReviverBox as public in your script and drag and drop appropriate GameObject in the UnityEditor. Then you can cache transform value to local variable: var reviverBoxTransform = ReviverBox.transform;