- Home /
1 collider 2 fuctions, how?
How to set a function to the upside part of the collider ?
i have an object with a collider, I want to the top part do some function, and the down part do other. how should i do that?
about the function, is about killing when jump on enemies head, I know how to do that.
i just dont know how to set to happens only in the top part of the collider. actually, in my game, i'm killing monster and losing life at the same time. i dont want in that way.
It'd be easier to use two seperate GameObjects with each having it's own collider, possibly in a parent-child hierarchy. If you really want it on one, then you'd have to decide which function to call by comparing the colliders' bounds,center.y, for example.
Great cherno, i will study about thouse bounds and center. I've already tried with 2 colliders and wouldn't work, since the child get properties of the collider from the parent. I'll try something here and if it works, i'll return.
Hey guys, that's what i want to do, just dont know how. take a look.
void OnCollisionEnter2D(Collision2D colisor)
{
if (colisor.gameObject.name.Equals("Player") // && downpart)
{
damage.Attack();
}
if (colisor.gameObject.name.Equals("Player") // && topPart)
{
RbPlayer.AddForce (new Vector2 (0, 150));
die= true;
}
}
Answer by Amanna · May 16, 2016 at 02:59 PM
you can use two gameObjects with separate boxCollider , and add two different scripts on that like ..
void OnCollisionEnter2D(Collision2D colisor) ///// in first script { if (colisor.gameObject.name.Equals("Player") // && downpart) { damage.Attack(); } }
void OnCollisionEnter2D(Collision2D colisor) /////// in second script { if (colisor.gameObject.name.Equals("Player") // && downpart) { damage.Attack(); } }