Activate Script not Working

I have this script attached to a spaceship:

var Whatever : GameObject;

function OnTriggerEnter (other : Collider) {

var scriptname : SeekSteer = Whatever.GetComponent(“SeekSteer”);

scriptname.active = true;

}

The space ship has a a box collider. The box collider has a Trigger. When I shoot the Collider with a bullet (that doesnt have a Trigger). Nothing happens. What am I doing wrong? I also tried attaching the script to another object, and it still doesnt work.

NOTE: The top 3 pictures show a few things about my object: http://unityimageprobs.wordpress.com/

Try removing the “” in GetComponent:

var scriptname : SeekSteer = Whatever.GetComponent(SeekSteer);

You should by the way cache this command.

var scriptname :SeekSteer

function Start(){
  scriptname = GameObject.Find("Whatever").GetComponent(SeekSteer);
}

function OnTriggerEnter (other : Collider) {
  scriptname.active = true;
}

I wonder though if you can find a component that is not active.

the script is a component, not an object, so maybe use .enabled instead of .active?

Make sure your bullet that is being shot has a collider and a rigid body.

straight from the Unity Reference Manual:

For a Trigger to collide with a normal Collider, one of them must have a Rigidbody attached. For a detailed chart of different types of collisions, see the collision action matrix in the Advanced section below.

try putting some Debug.Log(“DetectedCollision”); so you are SURE that the collision occured.
90% of the times the code isnt doing what you want, its because u are considering things that arent happening.

still, little info to give a propper answear

it probably means the speed of the bullet is too fast. On the bullet object, make sure it has the rigid body connected to it. and under the rigid body options there should be a Collision Detection option where you can select. discrete, continuous, or continuous dynamic, i would select either continuous or continuous dynamic, those two options you would want to use for fast moving objects to detect collision.

at the bottom of the unity window you should see it say debug log with the You collide me real hard.

I would adjust your script to this. Add a get tag to make sure that the object coming in contact with the ship is a bullet. Which means make a bullet tag in unity and make sure that the bullet object has that tag. otherwise anything that comes into contact with it will trigger the script. that might be the thing that is messing with you, is if you have the script deactivated something like the ground or something flying or whatever with a collider might be coming into contact and turns on the script.

var Whatever : GameObject;

function OnTriggerEnter (other : Collider) {
if (other.gameObject.tag == “bullet”) {
Debug.Log(“You collide me real hard”);
var scriptname : SeekSteer = Whatever.GetComponent(SeekSteer);
scriptname.active = true;
}
}

second I would make a dummy script named SeekSteer with just this code

function Update() {

Debug.Log (“SeekSteer scripted turned on”);

}

So that this is the script that is turned on. and if it is turned on in the debug log it will keep saying seek steer script turned on over and over and over so that you know you turned it on. Also I know you probably already did it, but make sure the script is unchecked that you want to turn on so it is intact deactivated

I’m pretty sure that you can’t access a disabled gameObject using GameObject.Find, can you? To check this, try putting the variable definition at the beginning of the script (like how fafase has suggested a few posts above). Then play your scene and then hit pause. Check the Inspector to see if the ‘SeekSteer’ Component is displayed for the variable ‘scriptname’.