What are you doing is that you are passing a String, to the LookAt. What is “MainCharacter”?
First of all you realy have to learn to declare the type of the variables, this will speed up your code reading a lot.
var distance : float = -10;
etc.
What does the target variable holds? What is this Transform? Target from the name shoud be the object, that the camera shoud be following. First of all you can’t search for a name of an object like (Variable = “MainCharacter”.
If you character is named “MainCharacter” then your code shoud be something like this:
var target : Transform = GameObject.Find("MainCharacter");
var distance : float = -10;
var lift : float = 1.5;
// var BuildTarget = "MainCharacter"; // You don't need this, since you have the target...
function Update ()
{
transform.position = target.position + Vector3(0, lift, distance); // We set the chamera to follow the target position
Transform.LookAt (target); // LookAt is looking at transform, not at String.
}
you had build target set to be a type of string by placing comments on it “” in the var declaration, ive changed it to a type of Transform, just drag the “mainCharcter” in to the BuildTarget variable in the inspector
also correctly declared your variables as an int and float type
you may want to replace BuildTarget with another name… like “player”
As you can see in the documentation here, the LookAt() function expects either an object (the target) or a position as its parameter. Here your variable is a String so “BuildTarget.position” is not defined either.
The easiest way to fix your problem is to affect your BuildTarget variable the actual object. You can do so by using the Unity interface via a simple drag and drop, or in your code by setting the variable from another script, or even by using Find:
BuildTarget = GameObject.Find("MainCharacter");
However, if you do use the Find function, just make sure to store the value once and then keep reusing the same variable, instead of calling it every frame (for performance reasons).