I'm trying to create a bunch of different game objects from a settings file I'm passing in at run time. I've checked and my game is reading in settings fine. But when I run the program, I get the following error:
ArgumentException: The prefab you want to instantiate is null.
But, I still get two cameras appearing in my scene. So I'm confused as to why this is happening.
Here is the code that is acting on the information received from the settings file:
public void CreateCamera()
{
for (int i = 0; i < testCamera.Count; i++)
{
camera = Instantiate(gameObject.AddComponent<Camera>(), new Vector3(0, 0, 0), Quaternion.identity) as Camera;
camera.name = testCamera[i].Name;
camera.near = Convert.ToSingle(testCamera[i].Near);
camera.far = Convert.ToSingle(testCamera[i].Far);
camera.aspect = Convert.ToSingle(testCamera[i].AspectRatio);
camera.fov = Convert.ToSingle(testCamera[i].FOV);
}
}
Following this, I also get the following message as well:
Can't add component 'Camera' to GameObject because such a component is already added to the game object!
Can anyone help me in fixing these issues?