Activate script in the parent

HI everyone! I have a Ford Pickup, in this object, i have “sub items”.

WheelRL
WheelRR
WheelFL
WheelFR
TRIGGER

In the trigger, i have this script:

var guiEnable = false;
var camioneta : GameObject;
// GUI
function OnGUI(){
GUI.depth = 0;
  if (guiEnable){
   GUI.Label(Rect(70,40,330,50), "Presiona F para entrar al coche");
  }
}
function OnTriggerEnter (myTrigger : Collider) { 
  if (myTrigger.name == "Player") guiEnable = true;
  if(Input.GetKey("f")){ 
// I need the code for activate the script "Conduccion"
  }
}

function OnTriggerExit (myTrigger : Collider) {
  if (myTrigger.name == "Player") guiEnable = false;
}

And, in the Ford Pickup, i have this script:

var rearWheel1 : WheelCollider;
var rearWheel2 : WheelCollider;
var frontWheel1 : WheelCollider;
var frontWheel2 : WheelCollider;
 
var steer_max = 20;
var motor_max = 10;
var brake_max = 100;
 
private var steer = 0;
private var motor = 0;
private var brake = 0;
 
function FixedUpdate () {
...
}

As I can activate from the object “son”, a script located in the parent object?

Thanks for your time :wink: :smile:

You can use GetComponent()

transform.parent.transform.GetComponent(YourScriptName).enabled = false; // (UnTested) But I think it would work

Hi, I may be wrong but,
Couldn’t you just do something like (in C#):

transform.parent.GetComponent<YourScript>().enabled = bool;

edit: did not see your answer, I agree with you

This code dont have error. I have one script in the “Forus Pickup” named: “Conduccion”. This script are desactivate.
The script “coches” not enable the script conduccion, location in the parent. The code in the script “coches” is this:

var guiEnable = false;
var camioneta : GameObject;
// GUI
function OnGUI(){
GUI.depth = 0;
  if (guiEnable){
   GUI.Label(Rect(70,40,330,50), "Presiona F para entrar al coche");
  }
}
function OnTriggerEnter (myTrigger : Collider) { 
  if (myTrigger.name == "Player") guiEnable = true;
  if(Input.GetKey("f")){ 
  transform.parent.transform.GetComponent(Conduccion).enabled = false; 
  }
}

function OnTriggerExit (myTrigger : Collider) {
  if (myTrigger.name == "Player") guiEnable = false;
}

but, this way, the script does not activate target …

You should use input In theUpdate function. I don’t think it will work in OnTriggerEnter.

Try the line without the condition.

OnTriggerEnter just happens on Trigger but OnTriggerStay may allow for Input.

Well, I went two errors: Line 12 (error in your code, but it should be pointed to the script). I think I can solve it alone, anything, ask

EDIT: I find the problem. I white bad the script

I just checked the line I wrote in a script of mine and it works fine. You can look for your script in a condition

(eg)

if(transform.parent.transform.GetComponent(Conduccion)) {
// I got you
transform.parent.transform.GetComponent(Conduccion).enabled = false;
print(name + " ParentName = " + transform.parent.transform…gameObject.name);
}

This will avoid the error cause it will only execute the code if the condition is met.

The line

transform.parent.transform.GetComponent(Conduccion).enabled = true;

Is fine :smile:
Thanks Mantis!