Same script not working on different objects

Hello! I have a problem and I’m stuck on how to solve it. I have a script that makes the camera move from one position to another.

using UnityEngine;
using System.Collections;

public class inspectworldscript : MonoBehaviour {
 
	public Vector3 desiredPosition;
	public int speed;
	public Camera camerax;

	void Start () 
	{
	
	}
	
	void Update () 
	{
           cameraMove();
	}

	public void cameraMove ()
	{
		camerax.transform.position = Vector3.Slerp(transform.position, desiredPosition, speed * Time.deltaTime);
	}
}

When I add this script component to the camera, it works perfectly fine. However, when I add it to a sprite, the camera moves to a position with an extremely different z value. What is going on???

Thank you for helping! :slight_smile:

You was using it wrong:

public Vector3 desiredPosition;
	public int speed;
	private float t;
	public Camera camerax;
	
	void Update () 
	{
		cameraMove();
	}
	
	public void cameraMove ()
	{
		camerax.transform.position = Vector3.Slerp(transform.position, desiredPosition, t);
		t += speed * Time.deltaTime;
		if(t > 1.0f)
				t= 1.0f;
	}