make camera follow prefab

I’m trying to get the main camera to follow a sphere. At first I managed to have the camera follow the ball with no problem. But since I’m gonna have the ball instantiated several times I turned the sphere into a prefab. But ever since I did that the camera won’t follow the ball anymore.

Here’s the code for the camera:

public var Ball : Transform;

public var cam : Vector3;

function Update () {
transform.position = Ball.position + cam;
}

I already assigned the prefab so the camera knows what it follows, but the camera doesn’t follow the ball. Why isn’t the camera following the ball like it should?

You have to tell the camera which ball to follow, when you instantiate a ball, you have created a new gameobject than the one you assigned to the camera before creating the prefab.

I already told the camera which ball to follow. I assigned the prefab to the camera to have it follow the prefab around, but the camera won’t follow the ball :frowning:

try dragging the camera on the ball from your hierarchy

add cam “smooth follow”(it in the assets script) and delete the rotation var (at all) from the scripts , i am sure this will work .

my friend if you create a new ball in the sense the smooth follow should not follow the original prefab it should follow the new clone , so it should be like this:

i figure out this solution to my self also just 1 min ago .

var new_player_prefab : Transform ;
var new_player : Transform ;

function Update ()

{

new_player = Instantiate(new_player_prefab,transform.position,transform.rotation,0);
Camera.mainCamera.GetComponent(SmoothFollow).target = new_player ;

}