Accessing another gameobject's collision?

I want to trigger a camera script when one object collides with another. The object is parent to the camera and a number of other “sub-objects”. I tried using a global variable like this:

object script:

static var objectCol = false;

function OnCollisionEnter (col : Collision) { 
   if (col.relativeVelocity.magnitude > collisionThreshold) {
		objectCol = true;
}
}

camera script:

function Update() {
	if (objectScript.objectCol == true) {
            doSomethingHere;
}
}

But that doesn’t work. What I’d like to do is to check for an object collision from the camera script, is that possible? Something like this pseudo code camera script:

function Update() {
    if (objectScript.objectCol.col.relativeVelocity.magnitude > objectScript.objectCol.collisionThreshold) {
        doSomethingHere;
}
}

The two other alternatives I’m thinking about doing are:

  1. to change the collider to the camera and make it the parent to the object, or
  2. put all the code for the camera script into the object script, since I can access the camera transforms from another object.

Any other ideas? Thanks!

Seems to me like it ought to work…though you should put this in objectScript:

function Start () {
    objectCol = false;
}

Because static variables don’t get reset automatically (i.e., once set to a value, it will keep that value even if you stop and run the scene again, unless you specifically set it otherwise). If that doesn’t fix it, are you sure objectCol is in fact being set to true?

–Eric

Thanks Eric, I missed that. But even without being re-set, for some reason it’s not picking up the variable.

Yeah, the script -should- work, but for some reason it doesn’t. Still digging around to figure out why…

EDIT: Got it! It was a stupid little typo that caused the problem. I had a bracket in the wrong spot which prevented the variable from being updated. Duh!