Search Unity

how do I find camera spawned into scene

Discussion in 'Editor & General Support' started by Vintage_Green, Sep 25, 2015.

  1. Vintage_Green

    Vintage_Green

    Joined:
    Mar 27, 2015
    Posts:
    22
    I have a camera prefab that is spawned into the scene at a specific location. The problem is when it is spawned in the camera is on, on the CCTV object Camera.

    Is there a way to both disable and find a camera that has been spawned into a scene.
     
  2. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    762
    You could try changing it's transform to be the child of an empty game object, and then get the children of that game object - though I'm not sure if you can find children that aren't active.
     
  3. Vintage_Green

    Vintage_Green

    Joined:
    Mar 27, 2015
    Posts:
    22
    OK this took bit to figure out. But for anyone who might want to know this in the future.

    Unity 5.2 how to find a camera Instantiated into the scene or in the scene in general.

    public GameObject CCTV_01_Clone;
    public GameObject CCTV_01_Prefab;

    public Camera CCTV_Camera;

    CCTV_01_Clone = Instantiate(CCTV_01_Prefab, curTarget.transform.position, curTarget.transform.rotation) as GameObject;

    CCTV_Camera = GameObject.FindWithTag("CCTV_1").GetComponent < Camera > ();
     
    Last edited: Oct 2, 2015