You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a player or AI misses a shot, the cannon balls falls off the screen. This asset stays spawned on the screen and is never deleted. This will impact performance as the Unity engine will continue to keep up with the assets (this can be many very quickly). The more objects that are spawned that are not deleted, the more impact to the performance.
The text was updated successfully, but these errors were encountered:
one possible fix, set a timeout for the projectile
using UnityEngine;
public class Projectile : MonoBehaviour
{
public int damage;
public bool friendly_projectile;
public float destroy_delay = 5f; // Time to wait before destroying the projectile
private float destroy_timer; // Timer to count down to destruction
private void Start()
{
// Start the timer when the projectile is instantiated
destroy_timer = destroy_delay;
}
private void OnCollisionExit(Collision collision)
{
if (collision.gameObject.TryGetComponent<IDamageable>(out var damageable))
{
// Damage the object if it is damageable
damageable.damage(damage, friendly_projectile);
// Reset the timer when the projectile collides with anything
destroy_timer = destroy_delay;
}
}
private void Update()
{
// Update the timer and destroy the projectile when it reaches zero
destroy_timer -= Time.deltaTime;
if (destroy_timer <= 0f)
{
Destroy(gameObject);
}
}
When a player or AI misses a shot, the cannon balls falls off the screen. This asset stays spawned on the screen and is never deleted. This will impact performance as the Unity engine will continue to keep up with the assets (this can be many very quickly). The more objects that are spawned that are not deleted, the more impact to the performance.

The text was updated successfully, but these errors were encountered: