Follow Camera

So when Ben was talking about the nastiness of declaring a string inside the code it got me thinking. Could you not just [SerializeField] GameObject player; and then inside unity if it changes you can reattach whatever you want that object to be?

So instead of doing the coding like Ben did I did just that and it works (so far) but my question is will it continue to work and did I just make my life easier or harder?

My code so far:

[SerializeField] GameObject player;

public class CameraFollow : MonoBehavior
{

void start ()

{

}

void LateUpdate()

{

transform.position = player.transform.position;

}

}

Id go with you made your life easier, as you can rename your player, and not even need to relink it. Plus you can also check at the start if the serializedfield is null, and shout warnings and so on

Privacy & Terms