I can’t seem to access the script on my camera after trying 10 different ways. Let’s just say there’s two GameObjects and a Script on both of the. I would like to change script B on object B with script A. For example; I have a player object with a script on him, and that script is trying change the value of a variable on a script attached to a camera. I can access the camera but can’t for the love of good change the variable on said script.
Any help is greatly appreciated!
public class MyScriptOnPlayerGO : MonoBehaviour
public MyScriptOnCameraGO myScriptOnCameraGoReference;
myScriptOnCameraGoReference = Camera.main.gameObject.GetComponent<MyScriptOnCameraGO>(); //you may not invlude this if you set the reference manually
public void ChangeSomeVariable()
myScriptOnCameraGoReference.someVariable = 40;
public class MyScriptOnCameraGO : MonoBehaviour
public int someVariable; //this got to be public
You may ignore the Awake() and just drag and drop on editor the Camera GameObject on the associated field.Cheers.