I have a project using 2D in which a character shoots projectiles, they are supposed to (among other things) collide with walls, and destroy on contact. My walls are sitting on a layer called “Walls Collide” and this is the code I have for the projectiles:
using UnityEngine;
using System.Collections;
public class Projectile : MonoBehaviour
{
public GameObject projHit;
void Start ()
{
}
void OnTrigger2D (Collider2D col)
{
if(col.gameObject.layer == 1 << LayerMask.NameToLayer ("Walls Collide"))
{
//if it hits a wall, get rid of it
Destroy (gameObject);
}
Unfortunately, the projectiles pass straight through the walls without any response, they have a circle collider as they are in fact round, any ideas how to fix this?