I am trying to write a script to create multiple cameras on one object.
public class CameraCreator : MonoBehaviour
{
public GameObject cam;
// Start is called before the first frame update
void Start()
{
for (int i=0; i<5; i++)
{
Camera cam = gameObject.AddComponent <Camera>() as Camera;
}
}
// Update is called once per frame
void Update()
{
}
}
I haven’t found out how to use lists in my case for components since my component is overwritten every time, can someone help me
or give me an example ?
Thank u for your answers. I’m brand new to Unity and struggle with the basics a bit.
I tried to create multiple objects this way :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraCreator : MonoBehaviour
{
// Start is called before the first frame update
public GameObject prefab;
void Start()
{
GameObject prefab = Resources.Load("Assets/Ressources/Main Camera.prefab") as GameObject;
for (int i=0; i<5;i++)
{
Instantiate(prefab, new Vector3(3*i,0,0), Quaternion.identity);
}
}
// Update is called once per frame
void Update()
{
}
}