find script on collision

Hi , If a object collides with a bullet (prefab) that contains a certain script, in this case, enemytrooper1, i want to access a variable of enemytrooper1, for some reason when i input the lines

function OnTriggerStay (other : Collider)
{
if (other.gameObject.GetComponent.())
{
//do something
}
}

it doesnt seem to find the fact that the bullet has collided with the other object, both colliders are present. I’ve never tried to access a script this way so not sure if i’m doing something wrong.

Thanks

you are missing the public variable in enemytrooper1
enemeytrooper1 needs to be the script name, not the object name

if (other.gameObject.getComponent().blablaVariable == something)
{
//do something
}

1 Like

the public variable is in the script and the script name is enemytrooper1

after running your example i get the error
null referenceexception : object reference not set to an instance of an object
enemybulletscript.ontriggerstay (unityengine.collider.other) (at asseets/enemybulletscript.js: 76)

when the bullet is instantiated it produces that error. which points to the line
if (other.GetComponent.().enemydirection==1)

i just cannot see whats wrong… any other ideas?

is enemydirection a public function in enemytrooper1.cs?
if it is, does it return an int?
it should look something like
sorry if I miss spell anything

class enemytrooper1 : monodevelop
{

public int getEnemyDirection()
{
return enemydirection;
}
}

then your if should look like this
if (other.GetComponent.().getEnemyDirection() == 1)

1 Like

the problem was i didnt have a rigidbody on the prefab, doing it this way i needed a rigidbody and worked… really appreciate your help, thanks

cool, glad you go it working