Hello, i have two scripts. One called “MouseOrbit” which is attached to my camera, and another script called “EnterVehicleScript” which is attached to my player.
Now what i want to do is:
//MouseOrbit Script
//Get this information
var target : Transform;
//EnterVehicleScript
//And use it in this script so i can change the target of "MouseOrbit" from within this script
var _enableVehicleEnter = false;
var isControllingPlayer = true;
var isControllingBoatVehicle = false;
//Transforms
var cam : Transform;
var player : Transform;
var boatVehicle : Transform;
function Start ()
{
cam.GetComponent("MouseOrbit");
//Make sure we are starting with controlling the player
isControllingPlayer = true;
}
function Update ()
{
//Enters the boat if button is pushed and if we are inside the collider
if (_enableVehicleEnter == true Input.GetButton("EnterVehicle"))
{
isControllingBoatVehicle = true;
}
//Make sure vehicleController and playerController can't be active at the same time
//If we are controlling the player
//If we are controlling the boat
if (isControllingBoatVehicle == true)
{
MouseOrbit.target = boatVehicle;
}
}
function OnTriggerEnter (EnableCol : Collider)
{
_enableVehicleEnter = true;
}
function OnTriggerExit (DisableCol : Collider)
{
_enableVehicleEnter = false;
}
I’ve been searching around for a little while and testing a few things, but haven’t had any luck so far. Can anyone help?
The code looks like this now
I tried moving the line around a bit, nothing changes though
#pragma strict
//Defining the target of my MouseOrbit Script
var MouseOrbitScript: MouseOrbit = GameObject.Find("Camera").GetComponent("MouseOrbit");
var _enableVehicleEnter = false;
var isControllingPlayer = true;
var isControllingBoatVehicle = false;
//Transforms
var cam : Transform;
var player : Transform;
var boatVehicle : Transform;
function Start ()
{
MouseOrbitScript.target = player;
cam.GetComponent("MouseOrbit");
//Make sure we are starting with controlling the player
isControllingPlayer = true;
}
function Update ()
{
//Enters the boat if button is pushed and if we are inside the collider
if (_enableVehicleEnter == true Input.GetButton("EnterVehicle"))
{
isControllingBoatVehicle = true;
}
//Make sure vehicleController and playerController can't be active at the same time
//If we are controlling the player
//If we are controlling the boat
if (isControllingBoatVehicle == true)
{
MouseOrbitScript.target = boatVehicle;
}
}
function OnTriggerEnter (EnableCol : Collider)
{
_enableVehicleEnter = true;
}
function OnTriggerExit (DisableCol : Collider)
{
_enableVehicleEnter = false;
}
I fixed it by putting
var MouseOrbitScript: MouseOrbit = GameObject.Find("Camera").GetComponent("MouseOrbit");
#pragma strict
//Defining the target of my MouseOrbit Script
var MouseOrbitScript: MouseOrbit;
var _enableVehicleEnter = false;
var isControllingPlayer = true;
var isControllingBoatVehicle = false;
//Transforms
var cam : Transform;
var player : Transform;
var boatVehicle : Transform;
function Start ()
{
MouseOrbitScript = cam.GetComponent("MouseOrbit");
MouseOrbitScript.target = player;
//Make sure we are starting with controlling the player
isControllingPlayer = true;
}
function Update ()
{
//Enters the boat if button is pushed and if we are inside the collider
if (_enableVehicleEnter == true Input.GetButton("EnterVehicle"))
{
isControllingBoatVehicle = true;
}
//Make sure vehicleController and playerController can't be active at the same time
//If we are controlling the player
//If we are controlling the boat
if (isControllingBoatVehicle == true)
{
MouseOrbitScript.target = boatVehicle;
}
}
function OnTriggerEnter (EnableCol : Collider)
{
_enableVehicleEnter = true;
}
function OnTriggerExit (DisableCol : Collider)
{
_enableVehicleEnter = false;
}