A question about references in C#

Despite reading everything I can find on the matter I can’t seem to figure this out. I have a camera called “standbyCamera” that is deactivated by a script called NetworkManager.cs. I have another script that is attached to the player called health.cs that I would like to reactivate it. Here are simplified versions of those scripts:

NetowkManager.cs:

using UnityEngine;
using System.Collections.Generic;

public class NetworkManager : MonoBehaviour {

    public GameObject standbyCamera; 

	public void SpawnMyPlayer () {
		standbyCamera.SetActive (false);
	}
}

Health.cs:

    using UnityEngine;
    using System.Collections;
    
    public class Health : MonoBehaviour {
    
    	public float HP = 100f;
    	public float currentHP;
        private NetworkManager _NetworkManager;
        public GameObject _standbyCamera; 
    	
    	void Start () {
    		currentHP = HP;
                _standbyCamera = GameObject.Find("standbyCamera")
    
    
    	[RPC]
    	public void TakeDamage (float amt) {
    		currentHP -= amt;
    		if (currentHP <= 0) {
    			Die ();
    		}
    	}
    
    	public void Die () {
    		_standbyCamera.SetActive (true); // This should be set to the same camera as the Network Manager script, but I don't know how to do that.
    	}
    }

Any help would be greatly appreciated. Thanks!

This is always fun. The problem is that once it is de-activated, a GameObject can’t be found with the Find command! I’m not sure how the rest of your program works, but I’d assume that the standbyCamera is either deactivated at startup (so it can’t find it) or is getting deactivated before the Start method in Health.cs runs.

Try making the standbyCamera in Health.cs as a private variable, making sure the standbyCamera is active in the inspector at game start, and defining the reference to it in the Awake method.

Alternatively, you could try to remove the Find command and simply link the standbyCamera to the Health.cs script in the editor. Or since it is a public variable, just access it directly from the NetworkManager.cs script.

You need to find the camera attached to the gameObject.

_standByCamera = GameObject.Find("standbyCamera").camera;

In NetworkView you don’t seem to initialise the camera, so make sure in all places you want to set it to active or no, that you do so.