using System.Collections; using System.Collections.Generic; using UnityEngine; public…
- User
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Arrow : MonoBehaviour { public int damage = 1; // Damage value
codevoid Start() { Invoke("Despawn", 3); } void Despawn() { Destroy(gameObject); } private void OnCollisionEnter2D(Collision2D collision) { // Check if the collided object has an EnemyHealth component attached to it EnemyHealth enemyHealth = collision.gameObject.GetComponent<EnemyHealth>(); if (enemyHealth != null) { enemyHealth.TakeDamage(damage); // Call the TakeDamage method of the enemyHealth Destroy(gameObject); // Destroy the arrow return; } // Check if the collided object has a BossHealth component attached to it BossHealth bossHealth = collision.gameObject.GetComponent<BossHealth>(); if (bossHealth != null) { bossHealth.TakeDamage(damage); // Call the TakeDamage method of the bossHealth Destroy(gameObject); // Destroy the arrow return; } }}
make it so if the arrows collide with the border layer the arrow will be destroyed
- Assistant
To make the arrows be destroyed when colliding with the border layer, you can add a check in the OnCollisionEnter2D method to see if the collision is with the border layer. Here's an updated version of the code:
csharp