Search Unity

Feedback Can't find DontDestroyOnLoad GameObjects

Discussion in 'Audio & Video' started by cristianangeldiaz, May 21, 2019.

  1. cristianangeldiaz

    cristianangeldiaz

    Joined:
    May 6, 2019
    Posts:
    3
    Hi everyone, I have a Unity proyect with two scenes, and I use DontDestroyOnLoad to conserve the GameObject Permanente beetween scenes.

    In the second scene, I´m trying to associate a camera object with a script. The problem is that both belong to different scenes in the Hierarchy and I can't do GameObject.Find to find the camera object.

    upload_2019-5-21_13-31-49.png

    Mod Window Size has the script component and Robot Camera is the camera that I need to attach to the script.

    This is the script code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Maximize_OnClick : MonoBehaviour
    6. {
    7.     public Camera cam_;
    8.     // Start is called before the first frame update
    9.     void Start(){
    10.         cam_ = GameObject.Find("Robot Camera").GetComponent<Camera>();
    11.     }
    12.  
    13.     public void MinOrMax(){
    14.         if (cam_.rect.height == 0.8){
    15.             cam_.rect = new Rect(1,1,1,1);
    16.         }
    17.         if (cam_.rect.height == 1){
    18.             cam_.rect = new Rect(0.65f,-0.45f,1,0.8f);
    19.         }
    20.     }
    21. }
    22.  
    I only want to change the size of the window modifying when I push a button child of Mod Window Size