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:
- to change the collider to the camera and make it the parent to the object, or
- 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!