- Home /
Checking trigger/collision of another gameobject separate from the one the script is on
Not sure how to word this exactly, so I'll just give a sample of code. I'm just wondering if there's a way to do this without making 2 scripts. I have a simple AI that paths around, and I want it to chase the player when he walks into a collision zone. So this script would be on the enemy
void onTriggerEnter(Collider coll){
if(coll.gameObject == player){
//do stuff
}
//so is there a way to do something like this, in this script?
it(chaseArea.coll.gameObject == player){
//do different stuff
//basically checking to see if someone collided with the chaseArea GO in the same script
}
}
Is there a simple solution to this? Or do I just need to make another script and reference it? I've been using unity for a while and I've never managed to figure this one out.
Thanks!
Not completely sure I understand the question.
Calls to enter, stay, and exit methods for triggers and collisions are only received by the objects with these methods in their scripts. For any given interaction, you have access to both parties involved. There can be no third party involved.
Note that OnTriggerEnter() starts with an upper case 'O'.
@ AlwaysSunny - I think you pretty much answered my question anyways, but here's another wording. EnemyScript is on EnemyGO. ChaseArea is a GO declared in the EnemyScript. I was asking if I could check if something collided with ChaseArea in the EnemyGO script, without doing it separately in a new script on the ChaseArea game object
@ Robertbu - Okay I know that, this script isn't copied from anything, just something I wrote in the chat box to illustrate it. $$anonymous$$y mistake
Answer by AngryBurritoCoder · Nov 14, 2014 at 10:00 AM
Why not just make one script and attach it to different objects that represent the zones, i do not know why you need different scripts ?
Your answer
Follow this Question
Related Questions
If gameObject's center passes through a trigger? 1 Answer
Mission Objectives 1 Answer
Trouble Descaling 2D object 1 Answer
Collecting Array items in order 1 Answer
Sphere and Cube collision won't work,Sphere vs Cube collision won't work 1 Answer