So, I'm quite new to game development and am trying to make a clone of flappy bird. The way my game operates is that I am spawning the pipes to the right of the camera, and then making it move all the way left until the camera cannot see it again, and place a square there that will collide with the pipes, destroy it and spawn it again to the right of the camera. Problem is, although the pipes can sense collisions, somehow when I use CompareTag(tag of the square) the collisions will not register at all. A debug message would not even load. They are both on the same layer so that can be eliminated. Here is the relevant code:
public class PipeSpawner : MonoBehaviour
{
// Start is called before the first frame update
float speed;
float ypos;
float spawnPoint;
float delay;
void Start()
{
speed = 1.5f;
spawnPoint = -0.03f;
}
// Update is called once per frame
void Update()
{
transform.position -= new Vector3(speed,0,0) * Time.deltaTime;
}
void SpawnPipe() {
ypos = Random.Range(-0.5f, 0.9f);
Instantiate(this.gameObject,new Vector3(spawnPoint,ypos,transform.position.z),Quaternion.identity);
}
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.CompareTag("Destroy")) {
Debug.Log("hit");
}
}
and here are the pics of the inspector
The Pipes:
https://i.sstatic.net/8e6SA.jpg, https://i.sstatic.net/WXk1q.jpg;
The Square:
https://i.sstatic.net/hJAOz.jpg
If anything about my question is confusing, please tell me and I will try to make it clearer to the best of my ability. Thanks in advance.