I’m making a simple enemy script {one that just walks around randomly & turns around if it hits a wall} that I plan on turning into a prefab later on so I can spawn multiple of them.
It’s going to have two colliders:
one underneath to tell the enemy whether or not to decrease its Y position {not using Unity’s physics}, & one in front of & inside of it to tell the enemy that it’s hit a wall & to turn around.
The problem I’m having is that, in the past when I’ve made multiple colliders for an object I would give them a static variable that the parent can access to see when they’ve collided with something.
static var onGround = 0;
function OnTriggerStay(other : Collider){
onGround = 1;
}
function OnTriggerExit(other : Collider){
onGround = 0;
}
which has worked fine for objects that don’t need to be turned into prefabs, but I imagine loading in multiple of the same enemy that all use the same static variable would make all of them think they’re colliding when one of them does.
After digging through answers to see if I could access the children’s script from the parent, I haven’t found anyone that seems to have the same problem.
I’ve also tried things like
parentTransform = GameObject.Find("enemy1").transform.position.y - 0.002;
& variations of code from people’s answers involving parentTransform, but it keeps giving me errors like “unknown identifier”.
Does anyone know how I can have the parent script detect a child’s collision, or have a child’s script change the parent’s Y position?
Remember, I’m limited to whatever code you can use in a prefab so I can’t rely on static variables.
Any help is appreciated ^-^