Should be using constant instead of magic string

In the video you comment and said you can’t do a rename on the string. The problem is you are actually using a magic string. The same string in two places. You should be looking at the same object. It should look like below.

  1. Then you could possibly make it public and control that object in your designer.
  2. You could change the string as you like.
  3. You could move it to a class so other places reference the same string, to protect against typos

private string PARENTOBJECT= “Defenders”;
private GameObject parent;
private Camera myCamera;

void Start()
{
    myCamera = GameObject.FindObjectOfType<Camera>();
    parent = GameObject.Find(PARENTOBJECT);
    if(!parent)
    {
        parent = new GameObject(PARENTOBJECT);
    }
}
1 Like