Using a script to alter part of another script

I am wanting my car to behave differently on the terrain to what it does on the car model. I have a script below which disables a script but i am unsure how to modify it. I am wanting the ‘Top Speed’ to Change in my ‘Car’ script on collision with ‘terrain’. Any ideas please?

var shouldBeEnabledOnStart = false;
function Start () {
    var scripts = gameObject.GetComponentsInChildren (Car, true);
   if (!shouldBeEnabledOnStart) {   
         for (var tmp : Car in scripts) {
             tmp.enabled = false;
         }
   }
   
   else {
      for (var tmp : Car in scripts) {
          tmp.enabled = true;
      }   
   
   }

}


function OnTriggerEnter (terrain : Collider) {
   
   if (terrain.gameObject.tag == "car") {
      var scripts = gameObject.GetComponentsInChildren (Car, true);
      for (var tmp : Car in scripts) {
          tmp.enabled = true;
      }
   }
}

function OnTriggerExit (terrain : Collider) {
   if (terrain.gameObject.tag == "car") {
   var scripts = gameObject.GetComponentsInChildren (Car, true);
      for (var tmp : Car in scripts) {
          tmp.enabled = false;
      }
   }
}

Anyone?

You can use SendMessage :

// Calls the function ApplyDamage with a value of 5
gameObject.SendMessage (“ApplyDamage”, 5);

// Every script attached to the game object
// that has an ApplyDamage function will be called.
function ApplyDamage (damage) {
print (damage);
}

I am not wanting to apply damage, i am wanting to modify another part of a script, in a similar way to adding time to a timer

var car : Car;

function OnTriggerEnter(terrain : Collider) { 	
	Car.topSpeed = 50;
}

the error i get from the above code is:
an instance of type 'Car" is required to access not static member ‘topSpeed’

I can’t work out what you’re trying to do here?

access a variable in another script?

Hint. Don’t disable gameobjects if you’re using FindObject/GetComponent, etc. It can’t find them, so better to keep a reference to them, if you plan to do that.

Im using the car script from the car tutorial and one of the variables you can set is ‘top speed’. i am wanting the cars top speed to change when it enters a trigger. ie make it act differently on different surfaces. The top speed variable is located within the script called car. if that makes sense?

First thing you do in Start() is disable all the Car scripts from what I can tell.

Is this script a controller script that controls multiple cars?

If you do find the Car component script (call it something else so it doesn’t confict with a class name, like carScript)
It should just then be
carScript.maxSpeed = 50;

Debug.Log() is worth using to find out what is going on.

That car tutorial is quite complex, and tough to tweak. This tutorial was lot easier to play around with.
http://www.gotow.net/andrew/blog/?page_id=78

solved!

var car : Car;

function OnTriggerEnter(terrain : Collider) { 	
	car.topSpeed = 1;
	car.maximumTurn = 10;
	car.minimumTurn = 5;
}

function OnTriggerExit(terrain: Collider) {
	car.topSpeed = 400;
	car.maximumTurn = 18;
	car.minimumTurn = 12;
}

works to change top speed and handling in the sense of car turning