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); } } }
Barrier's properties. Will post more chicks in a sec.
Adrian Perez
Shot properties. I understand the rigidbody probably isn't necessary but I've tried every combination and it doesn't work.
Liam Sanchez
...
David Murphy
bump
Ayden Moore
Cheers boss.
Adam Clark
I've also tried every combination of "is trigger" and shit. Nothing wants to work.
Julian Richardson
I've even tried removing the if statement. Just doesn't call the function at all.
Justin Ross
Would greatly appreciate any help. Tried googling and adjusting and shit but nothing worked.
Jonathan Martinez
make an not-shit hrpg but in English
Connor Gray
Sauce?
Justin James
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
Jaxson Lewis
Also. Almost forgot, if you set a collider to is trigger, change on collision enter to OnTriggerEnter instead
Adam Gray
Have you tried OnTriggerEnter2D?
Robert Myers
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?
Easton Rodriguez
Forgot pic. Sorry.
Adam Cox
Not sure what you mean. Can you give a few details about what your trying to do?
Luis Wright
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..
Nathan Foster
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.
Andrew Garcia
Or would 4 edge colliders be a lighter option than a box collider?
Cameron Brown
If you use OnTriggerExit2D, it should call when the object leaves the trigger collider.
Justin Bell
Forgot pic. Rip
Mason Wright
Oh yeah that's right. Still wondering if it would be lighter to have 4 edge colliders as opposed to the box collider.
Luis Powell
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
Isaac Long
performance wise it won't matter that much, If you are interested in the edge vs box collider check out this link:
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).
Benjamin Morris
Mmmm nevermind. Pretty sure I'm retarded. Thanks an absolute ton to everyone who's helped.