Best way to detect specific collisions in child objects

Hi all,

I am making my 1st game and right now, I have a simple game were two players need to jump on the other’s head to kill him. It’s a 2 player game. Pretty basic as you can see.

I am currently using hitboxes on the head child and feet children of the Player1 and Player2 gameobjects. I made triggers on both, places feets and heads in a different layer, and if there is a collision, it triggers a script. This script is triggered by both, so I check the highest one with transform.y positions to kill the right one.

The problem is that I want to have multiple characters in my fighting game, not only two, and right now, the trigger script cannot be on both gameobjects (playey1 and player2) as it would trigger twice (for everything, like score, animations, etc).

I would like to replace the triggers with OnCollisionEnter2D or something like that. Is there a way to check if the head has been hit without rigibodies (as feets and heads should not collide with the word and should not affect the characters) and without triggers? Then, if the head has been hit, to give the point to the right player and destroy the other gameobject?

I need something that could be in all characters scripts OR something that would be on none. Right now, I have a GameMaster empty gameobject with a couple of scripts on it. If I could check that specific collision and manage what happen to both players from it, it would be really nice.

I hope I’m not too lost for simple answers haha.

Thanks anyway guys and gals!

you will need if statements to check some info about the other object. if something jumps on your head… this will destroy whichever object is lower if your position Y is up.

function OnCollisionEnter2D(otherguy: Collision2D) { 

or maybe you can check the object name before you so something??? this should work:

    var timesiwaskicked=0;  
    function Update(){

function OnCollisionEnter2D(otherguy: Collision2D) {                     	

hopefully this gets you thinking in the right direction.

and for the other part of your question.
if you want to send data to your master object…i will assume the object “Game Master” has a script attached called “Brain”, and there is a variable in it called “playerone”.

var bigmaster:GameObject:
var brainscript:Component;

bigmaster=GameObject.Find("Game Master");


this will change a variable in your game master object from any script, anywhere. it works with the webplayer but idk about flash.

i got a cool solution
////////////////////////////////// in parent :

     public  void OnCollisionEnter2D(Collision2D coll)
// virtual to override it in child class 
     public virtual void WhenColliding(Collision2D coll)
                print("ther parent is talking");
///////////////////////////////////////////////and in child class 

    public void WhenColliding(Collision2D coll)
        print("child is talking");