object reference not set to instance of object?

i want to script a simple door but iget this object reference error , im a noob at scripting so bare with me
this is what ive got so far

public var door : GameObject;
public var closedpoint : GameObject;
public var openpoint : GameObject;
public var canopen : boolean = false;
public var speed : float = 1.0;

function Update ()
{

}

function ActivateObject()
{
print(“activated”);
if (canopen)
{
var target = openpoint;
door.transform.position = Vector3.MoveTowards(door.transform.position,target.position,speed * Time.deltaTime);
}
}

It looks like openpoint or door variable are not assigned.

they r assigned in the inspector, weird:(

target .position // whitespace also in your code?

And you dont really need the target variable, if you’re just going to assign openpoint to it.

door.transform.position = Vector3.MoveTowards(door.transform.position, openpoint.transform.position,speed * Time.deltaTime);

tnx for the replies but no the space isnt in my code
and its still not working im going insane :slight_smile:

openpoint is a GameObject.

target.transform.position is what you need and not target.position.

Also, as far as I know, MoveTowards needs to be in Update() or a coroutine.

tnx fluzing got it working now much appreciated