Hi,
I have been trying to create a script that I can use on every vehicle in my game which works fine until it is on two objects.
As soon as it is on two objects the second script (to be put onto an object) no longer switches camera.
Each vehicle will have up to 7 cameras ( hence testing if camera is there )
How do I stop the script interacting with other versions of itself?
// seat position
var driver_seat : Transform;
var seat_1 : Transform;
var seat_2 : Transform;
var seat_3 : Transform;
var seat_4 : Transform;
var seat_5 : Transform;
var seat_6 : Transform;
// turret and ship cams
var ship_cam : Camera;
var cam1 : Camera;
var cam2 : Camera;
var cam3 : Camera;
var cam4 : Camera;
var cam5 : Camera;
var cam6 : Camera;
// timer
var timer : int = 30;
// ship
var ship : GameObject;
// active control vars
private var state : int = -1;
// player position & cam
var play : Transform;
var player_cam : Camera;
function Update ()
{
timer = timer - 1;
if ( Input.GetAxis ("e_key") && state == -1 && timer < 0)
{
timer = 30;
if (driver_seat != null)
{
if(Vector3.Distance (driver_seat.position, play.position ) < 1.5 )
{
state = 0;
ship.BroadcastMessage ("Activate_Turret", 0);
}
}
//
if (seat_1 != null)
{
if(Vector3.Distance (seat_1.position, play.position ) < 3 )
{
state = 1;
ship.BroadcastMessage ("Activate_Turret", 1);
print ("a");
}
}
//
if (seat_2 != null)
{
if(Vector3.Distance (seat_2.position, play.position ) < 1.5 )
{
state = 2;
ship.BroadcastMessage ("Activate_Turret", 2);
}
}
//
if (seat_3 != null)
{
if(Vector3.Distance (seat_3.position, play.position ) < 1.5 )
{
state = 3;
ship.BroadcastMessage ("Activate_Turret", 3);
}
}
//
if (seat_4 != null)
{
if(Vector3.Distance (seat_4.position, play.position ) < 1.5 )
{
state = 4;
ship.BroadcastMessage ("Activate_Turret", 4);
}
}
//
if (seat_5 != null)
{
if(Vector3.Distance (seat_5.position, play.position ) < 1.5 )
{
state = 5;
ship.BroadcastMessage ("Activate_Turret", 5);
}
}
//
if (seat_6 != null)
{
if(Vector3.Distance (seat_6.position, play.position ) < 1.5 )
{
state = 6;
ship.BroadcastMessage ("Activate_Turret", 6);
}
}
}
// get out of turrets
if ( Input.GetAxis ("e_key") && state > -1 && timer < 0)
{
state = -1;
timer = 30;
BroadcastMessage ("Activate_Turret", -1);
}
// switch cameras
// player cam
if (state == -1)
{
player_cam.GetComponent("Camera").active = true;
}
else
{
player_cam.GetComponent("Camera").active = false;
}
// cam 0
if (ship_cam != null)
{
if (state == 0)
{
ship_cam.GetComponent("Camera").active = true;
}
else
{
ship_cam.GetComponent("Camera").active = false;
}
}
//cam 1
if (cam1 != null)
{
if (state == 1)
{
cam1.GetComponent("Camera").active = true;
}
else
{
cam1.GetComponent("Camera").active = false;
}
}
//cam 2
if (cam2 != null)
{
if (state == 2)
{
cam2.GetComponent("Camera").active = true;
}
else
{
cam2.GetComponent("Camera").active = false;
}
}
}