Question by
RensDevolp · Oct 07, 2015 at 11:13 AM ·
scripting problementer-car
How to apply this enter/exit plane script on other cars
hi everyone,
i made this airplane enter/exit script. it works fine, but when i place another aircraft in the scene, it does not work. the player is attached to the second plane, but the player does not get inactive. you can fly the plane, however, with the player still on the ground, moving with the plane. i set the var's from the other plane right.
please help!
here's my script: using UnityEngine; using System.Collections;
public class JetEnterScript: MonoBehaviour {
public Component [] EnableComponents; //drag your scripts or whatever component you whant to disable here.
public string PlayerTag;
public KeyCode ActivatorKey;
public GameObject Player;
public GameObject PlaneCam;
public GameObject EnterPoint1;
public bool InAircraft;
private bool Trigger;
public WheelCollider[] wheelcolliders;
public float BrakeTorque;
void Start(){
InAircraft = false;
}
void Update(){
if (InAircraft) {
if (Input.GetMouseButtonDown (0)) {
foreach (WheelCollider WC in wheelcolliders) {
WC.brakeTorque = BrakeTorque;
}
}
if (Input.GetMouseButtonUp (0)) {
foreach (WheelCollider WC in wheelcolliders) {
WC.brakeTorque = 0;
}
}
}
//_________________________________________________________________________________
if (Trigger && Input.GetKeyDown(ActivatorKey)) {
InAircraft = true;
foreach (MonoBehaviour mo in EnableComponents) {
mo.enabled = true;
}
PlaneCam.SetActive (true);
Player.SetActive (false);
Player.transform.parent = EnterPoint1.transform;
Trigger = false;
} else{
if (Input.GetKeyDown(ActivatorKey)) {
foreach (MonoBehaviour mo in EnableComponents){
mo.enabled = false;
}
PlaneCam.SetActive (false);
Player.SetActive (true);
EnterPoint1.transform.parent = null;
}
}
}
void OnTriggerEnter(Collider target){
if (target.tag == PlayerTag) {
Trigger = true;
}
}
void OnTriggerExit(Collider target){
if (target.tag == PlayerTag) {
Trigger = false;
}
}
}
Comment
Perhaps it has something to do with line 46? maybe put: if ((Trigger == false)&&(Input.Get$$anonymous$$eyDown(Activator$$anonymous$$ey)))