For some reason, sometimes when the player shoots the bullet is deleted immediately after shooting. It looks as if it is colliding with something so I debug.logged it but it doesn’t seem to be hitting anything that would delete it.
This is the code for shooting
public float damage;
public float travelLimit;
public Rigidbody2D rb;
public GameObject player;
private void Update()
{
if(Vector2.Distance(transform.position, player.transform.position) >= travelLimit)
{
Destroy(gameObject);
}
}
private void OnTriggerEnter2D(Collider2D other)
{
SpiderEnemyBehaviour spiderEnemy = other.GetComponent
<SpiderEnemyBehaviour>();
if(spiderEnemy != null)
{
spiderEnemy.TakeDamage(damage);
Destroy(gameObject);
}
if(other != null)
{
Debug.Log($"Bullet hit {other.name}");
}
}
private void OnCollisionEnter2D(Collision2D other)
{
if (other != null)
{
Debug.Log($"Bullet hit {other.collider.name}");
}
}