- Home /
Question by
wind-driver · Feb 01, 2018 at 04:04 PM ·
2dcollision2d game2d-platformer2d-physics
2D Detect collisions of a 2D block only on left/right (not top/bottom)
In my game, i use block whitch can move on the left/right and i want them to disappear when they touch the left or right side of a ground. But if i summon my block on (or if they move to) the top of a ground, they disappear because i don't know how to say to the program that the block isn't touching the left or right side.
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Collision : MonoBehaviour { void OnCollisionEnter2D(Collision2D coll) { if (coll.gameObject.tag == "Ground" && gameObject.name == "blocSpawn(Clone)") { Destroy(gameObject); } } }
Thank you guys for your advices !
Comment