Unity crashes when accessing a function of a script from another script

Hey guys!
I’m trying to access a function of a script from another script.
My first script EnterVehicle.cs calls the SetTarget function of FollowCamera.cs like this:


SetTarget is declared as follows:

  public void SetTarget(Transform _target)
    	target = _target;

Unity keeps crashing when I call SetTarget from my EnterVehicle script.

Unity has been really unstable since I updated: I don’t get any runtime errors unity just freezes and I have to close it from the task manager.

Has anybody got an idea what I’m doing wrong?
Thanks in advance,

Stupid me! facepalm
Forgot to assign the Transform for the vehicle in the editor.
But I still got the problem that Unity just freezes instead of giving me a NullReferenceException.

I might be wrong with this but what i see is that your method is not static so you need a reference to the script object.

var camScript = mainCamera.GetComponent<FollowCamera>();

And then you can perform actions with your FollowCamera script.