I have a turret that I want to mount on the side of a ship. When i go up to a computer I want to be able to hit e and the player can take control of it. I have three seperate scripts. the first on goes onto the computer.
var showGUI : boolean;
var other : Transform;
var controlingturret=false;
function OnMouseEnter()
{
showGUI = true;
}
function OnMouseExit()
{
showGUI = false;
}
function OnGUI()
{
if (showGUI)
{
GUI.Box(Rect(20, 10, 150, 100), "Press E to Enter");
if (Input.GetButtonDown("Use")){
GameObject.FindWithTag("turret1").GetComponent(TurretControl).enabled=true;
GameObject.FindWithTag("Player").GetComponent(which).DoSomething();
controlingturret=true;
}
}
}
if (controlingturret){
if (Input.GetButtonDown("Use")){
GameObject.FindWithTag("turret1").GetComponent(TurretControl).enabled=false;
GameObject.FindWithTag("Player").GetComponent(which).DoSomethingAgain();
controlingturret=false;
}
}
the second goes onto the player to control the camera selection
var cam1 : Camera;
var cam2 : Camera;
function Start () {
cam1.enabled=true;
cam2.enabled = false;
}
function DoSomething() {
cam1.enabled=false;
cam2.enabled = true;
}
function DoSomethingAgain() {
cam1.enabled=true;
cam2.enabled=false;
}
and the third goes onto the turret itself
var horizontalSpeed = 2.0;
var verticalSpeed = 2.0;
function Start (){
GetComponent(TurretControl).enabled=false;
}
function Update ()
{
// Get the mouse delta. This is not in the range -1...1
var h = horizontalSpeed * Input.GetAxis ("Mouse X");
var v = verticalSpeed * Input.GetAxis ("Mouse Y");
transform.Translate (h, 0, v);
}
So far I am able to get into the turret and control it just fine but i'm not able to take control of the player again. Am I going about this the wrong way? Is there a more effective way to do it? Anyone got any help? Thanks