camera follow error

i have 4 different character/player , i can swap move these player i want my camera follow to these player but i don’t how to do that

can anyone help me!

basically, i’m using following but they getting me error

var Target : Transform;
private var players : Array;
var distance = 3;

function Start ()
{
players = new Array();
players[0] = GameObject.Find("C1");
players[1] = GameObject.Find("C2");

players[0].active = true;
players[1].active = false;
}



function LateUpdate ()
{
if (player[0].active.true)
   transform.position = Target.position + Vector3(10, distance, 0);
    transform.LookAt (0);
	else
	transform.position = Target.position + Vector3(10, distance, 0);
    transform.LookAt (1);
}

please anybody tell me what wrong this code

The “if” statement needs to have braces around the enclosed code:-

if (player[0].active.true) {
   transform.position = Target.position + Vector3(10, distance, 0); 
   transform.LookAt (0);
}
else {
   transform.position = Target.position + Vector3(10, distance, 0); 
   transform.LookAt (1); 
}

hey still have same error

i adding this script in to the camera is that right also for the swapping i using a different script

1 error
Assets/NewBehaviourScript 1.js(19,21): BCE0044: expecting ), found ‘.’.

2 error
Assets/NewBehaviourScript 1.js(19,22): BCE0043: Unexpected token: true.

3 error
Assets/NewBehaviourScript 1.js(20,23): BCE0044: expecting :, found ‘=’.

if (player[0].active.true)
if (player[0].active == true)

unity still getting error:
really i don’t understand whats wrong

error:
Assets/NewBehaviourScript 1.js(25,21): BCE0023: No appropriate version of ‘UnityEngine.Transform.LookAt’ for the argument list ‘(int)’ was found.

Thats because you need to put a vector in the LookAt() function and not just 1 or 0!
Like Target.position or something like this.

Greg

i think what you say (may be) is wrong…

You’ve actually just missed out the players array:-

transform.LookAt(players[0]);

hey amunity
can you solve this problem because i am using same thing. but they getting me error also i trying above code but doesn’t work.

camera can not be follow any player

if you got the answer please show me

sorry man but you true the above code doesn’t work

i try to figured out but i don’t know how to solve this

please help me

var Target : Transform;
private var players : Array;
var distance = 3;

function Start ()
{
players = new Array();
players[0] = GameObject.Find("C1");
players[1] = GameObject.Find("C2");

players[0].active = true;
players[1].active = false;
}



function LateUpdate ()
{
if (players[0].active == true) {

   transform.position = Target.position + Vector3(10, distance, 0);
    transform.LookAt (players [0] );
	}
   else {
   transform.position = Target.position + Vector3(10, distance, 0);
    transform.LookAt (players[0]);
	}
}

following error coming i don’t know what that meaning

MissingMethodException: Method not found: ‘UnityEngine.Transform.LookAt’.
Boo.Lang.Runtime.MethodDispatcherFactory.ProduceExtensionDispatcher ()

Try using

transform.LookAt (players[0].transform);

i thing this is a good way to learn scripting

i try to put above code in my code but unity show some target problem saying go to the main camera hierarchy and assign target variable but i have two player that’s what i using array if condition

if i assign the target then camera follow only assign player

otherwise unity shown following errors

  1. null reference

UnassignedReferenceException: The variable Target of ‘NewBehaviourScript 1’ has not been assigned. This happened in the game object “Main Camera”.
You probably need to select the “Main Camera” in the hierarchy and assign the Target variable of the NewBehaviourScript 1 script in the inspector.

[/img]