So I have a bomb that when it’s detonated, creates two fires on opposites sides of the bomb, and I want the fire to make damage only if there isn’t any escenary between the fire and an object. I’ve tried the following but it doesn’t detect the object. I’m quite new to raycasting so sorry if this is stupid.
public int enemyDamage;
public int objectDamage;
public GameObject bullet;
bool count = false;
float timer;
public void OnTriggerEnter2D(Collider2D hitInfo)
{
DestructableObject destructableObject = hitInfo.GetComponent<DestructableObject>();
Enemy enemy = hitInfo.GetComponent<Enemy>();
CharacterHealth player = hitInfo.GetComponent<CharacterHealth>();
if (destructableObject != null)
{
RaycastHit2D hit = Physics2D.Raycast(transform.position, hitInfo.transform.position - transform.position);
if (hit.collider != null && hit.collider.CompareTag("Destructable") )
{
destructableObject.TakeDamage(objectDamage);
}
}
if (enemy != null)
{
enemy.TakeDamage(enemyDamage);
}
if (player != null)
{
player.TakeDamage(enemyDamage);
}
count = true;
}
private void Update()
{
bullet.GetComponent<Rigidbody2D>().gravityScale = 0;
bullet.GetComponent<Rigidbody2D>().velocity = new Vector2(0f, 0f);
bullet.GetComponent<Rigidbody2D>().angularVelocity = 0;
if (count)
{
timer += 1 * Time.deltaTime;
}
if (timer >= 3)
{
Destroy(bullet);
}
}