I’m trying to make it to when the character hits an object, the script’s value in the camera, smooth follow, will change. Here’s what I have so far:
var maincamera : GameObject;
var cameratrigger : GameObject;
function OnControllerColliderHit( hit : ControllerColliderHit)
{
if (hit.gameObject.transform.name == "Cameratrigger")
{
maincamera.GetComponent("Smooth Follow").Height = 1.5;
}
}
I’m getting the error “NullReferenceException: Object reference not set to an instance of an object”. What’s wrong here.
What line does the error refer to? (You can see the line listed at the end of the error dialog)
Have you actually defined maincamera and cameratrigger in the inspector, and made sure that maincamera has a component named “Smooth Follow”?
Those questions being asked, you have to look at a script itself, not the script name in the inspector, to see what the script is called. In your case you’re probably looking for SmoothFollow, not Smooth Follow, since scripts typically don’t have spaces in their names.
The error saying Height doesn’t exist probably means that the variable is misnamed and is actually all-lowercase in the SmoothFollow script. Just change “Height” to “height”. One mechanic for naming variables is to always start with a lowercase and use capitals for new words (i.e. mainCamera, height, myNewVariable). Functions, in contrast, start with a capital (i.e. Update, GetComponent).