Posted on here before and got some helpful advice. Working with unity on a shitty little game idea I've got...

Posted on here before and got some helpful advice. Working with unity on a shitty little game idea I've got. Using the 2d engine but can't seem to make my script on my box collider to call.

Code on the barrier

using UnityEngine;
using System.Collections;

public class Barrier : MonoBehaviour
{
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("PlayerShot"))
{
Destroy(collision.gameObject);
}
}
}

Other urls found in this thread:

answers.unity3d.com/questions/1221338/edgecollider2d-or-boxcollider2d.html
twitter.com/NSFWRedditImage

Barrier's properties. Will post more chicks in a sec.

Shot properties. I understand the rigidbody probably isn't necessary but I've tried every combination and it doesn't work.

...

bump

Cheers boss.

I've also tried every combination of "is trigger" and shit. Nothing wants to work.

I've even tried removing the if statement. Just doesn't call the function at all.

Would greatly appreciate any help. Tried googling and adjusting and shit but nothing worked.

make an not-shit hrpg but in English

Sauce?

Make sure one of the colliders is set to is trigger. Try if (other.gameObject.tag == "PlayerShot") instead. If it still doesn't work. Try making sure the script is on the is trigger object

Also. Almost forgot, if you set a collider to is trigger, change on collision enter to OnTriggerEnter instead

Have you tried OnTriggerEnter2D?

Noticed I had it as PlayerShot instead of playerShot. Changed to your edit, script on barrier with is trigger on, still nothing.

Changed to OnTriggerEnter2D, still nothing.

Just did. Didn't work.

Just added a rigidbody to the shot and it seems to have actually fucking worked. Except only issue is the trigger consumes the entire area of the square, rather than the edges. There a way to change that without having 4 edge colliders?

Forgot pic. Sorry.

Not sure what you mean. Can you give a few details about what your trying to do?

Problem is, that ur using is trigger while the code is on collision.. it should be on trigger enter if you're trying to do it with trigger..

Attempted it without it being a trigger and still got nothing. Cheers for the info, though :)

Basically I want the shots to disappear when they hit the green line. Right now they're disappearing anywhere inside the green box. I wanna know if there's a way to change it to collide only at the green lines without using edge colliders.

Or would 4 edge colliders be a lighter option than a box collider?

If you use OnTriggerExit2D, it should call when the object leaves the trigger collider.

Forgot pic. Rip

Oh yeah that's right. Still wondering if it would be lighter to have 4 edge colliders as opposed to the box collider.

My guess would be there's not much difference performance wise between the two. And having only the single collider would be easier to manage. It's is basically your play area that you can use for any object you may want to destroy upon leaving the game area

performance wise it won't matter that much, If you are interested in the edge vs box collider check out this link:

answers.unity3d.com/questions/1221338/edgecollider2d-or-boxcollider2d.html

Exactly what I wanted. Thanks a lot for that. Greatly greatly appreciated.

I figured there wouldn't be much but I just wanted to check out the specifics. Good to know stuff.

One more question, is there a way to spawn a prefab in a certain position according to the parent and add it to an array? (Last part's probably simple).

Mmmm nevermind. Pretty sure I'm retarded. Thanks an absolute ton to everyone who's helped.