considerando i seguenti script voglio che appena gli enemy raggiungono il punto designato sia possibile scegliere dall' ispector delle immagini da dissolvere diverse in base all enemy, vorrei inoltre fosse possibile scegliere il punto di arresto di ogni enemy"using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;

public class dissolvenzaImmagini : MonoBehaviour
{
    [Header("Sequence Settings")]

    public GameObject[] initialImages;        // Images to show at the beginning

    public GameObject[] enemyPrefabs;         // Array of enemy prefabs
    public Transform[] enemySpawnPoints;      // Spawn points for each enemy

    public GameObject[][] imagesBeforeSpawn;      // Images to fade in before each enemy spawns
    public GameObject[][] imagesOnEnemyReach;     // Images to fade when each enemy reaches the player
    public GameObject[][] imagesAfterEnemyDeath;  // Images to fade in after each enemy dies

    public GameObject[] finalImages;          // Images to fade in after all enemies are defeated

    [Header("Fade Settings")]
    public float fadeDuration = 3f;           // Duration of the fade
    public float displayDuration = 2f;        // Duration to display the images

    [Header("Player and Enemy Settings")]
    public Transform playerTransform;         // Reference to the player's Transform
    public controller playerMovement;         // Reference to player movement script
    public Player_combat_Mattina combat;      // Reference to player combat script
    public enemySpawner[] enemySpawners;      // References to enemy spawners

    private int currentSequenceIndex = 0;     // Index to track the current enemy sequence
    private GameObject currentEnemy;          // Reference to the current enemy

    void Start()
    {
        // Initialize images by setting their alpha to 0
        SetGroupAlpha(initialImages, 0f);
        SetGroupAlpha(finalImages, 0f);

        // Initialize the arrays of image groups
        InitializeImageGroups(imagesBeforeSpawn);
        InitializeImageGroups(imagesOnEnemyReach);
        InitializeImageGroups(imagesAfterEnemyDeath);

        DisablePlayerAndEnemies();
        StartCoroutine(RunSequences());
    }

    void InitializeImageGroups(GameObject[][] imageGroups)
    {
        if (imageGroups != null)
        {
            foreach (var group in imageGroups)
            {
                SetGroupAlpha(group, 0f);
            }
        }
    }

    void DisablePlayerAndEnemies()
    {
        if (playerMovement != null) playerMovement.enabled = false;
        if (combat != null) combat.enabled = false;

        foreach (enemySpawner spawner in enemySpawners)
        {
            if (spawner != null) spawner.enabled = false;
        }
    }

    void EnablePlayerAndEnemies()
    {
        if (playerMovement != null) playerMovement.enabled = true;
        if (combat != null) combat.enabled = true;

        foreach (enemySpawner spawner in enemySpawners)
        {
            if (spawner != null) spawner.enabled = true;
        }
    }

    IEnumerator RunSequences()
    {
        // Fade in initial images if any
        if (initialImages.Length > 0)
        {
            yield return StartCoroutine(FadeInGroup(initialImages));
            yield return new WaitForSeconds(displayDuration);
            yield return StartCoroutine(FadeOutGroup(initialImages));
        }

        // Loop through each enemy sequence
        while (currentSequenceIndex < enemyPrefabs.Length)
        {
            // Fade in images before spawning enemy
            if (imagesBeforeSpawn.Length > currentSequenceIndex && imagesBeforeSpawn[currentSequenceIndex].Length > 0)
            {
                yield return StartCoroutine(FadeInGroup(imagesBeforeSpawn[currentSequenceIndex]));
                yield return new WaitForSeconds(displayDuration);
                yield return StartCoroutine(FadeOutGroup(imagesBeforeSpawn[currentSequenceIndex]));
            }

            // Spawn the enemy and wait for it to be defeated
            yield return StartCoroutine(SpawnAndHandleEnemy(currentSequenceIndex));

            // Fade in images after enemy death
            if (imagesAfterEnemyDeath.Length > currentSequenceIndex && imagesAfterEnemyDeath[currentSequenceIndex].Length > 0)
            {
                yield return StartCoroutine(FadeInGroup(imagesAfterEnemyDeath[currentSequenceIndex]));
                yield return new WaitForSeconds(displayDuration);
                yield return StartCoroutine(FadeOutGroup(imagesAfterEnemyDeath[currentSequenceIndex]));
            }

            currentSequenceIndex++;
        }

        // Fade in final images after all enemies are defeated
        if (finalImages.Length > 0)
        {
            yield return StartCoroutine(FadeInGroup(finalImages));
            yield return new WaitForSeconds(displayDuration);
            yield return StartCoroutine(FadeOutGroup(finalImages));
        }

        // Re-enable player and enemies
        EnablePlayerAndEnemies();
    }

    IEnumerator SpawnAndHandleEnemy(int index)
    {
        // Spawn the enemy
        currentEnemy = Instantiate(
            enemyPrefabs[index],
            enemySpawnPoints[index].position,
            Quaternion.identity);

        // Set up the enemy's movement and target
        EnemyMovement movement = currentEnemy.GetComponent<EnemyMovement>();
        if (movement == null)
        {
            movement = currentEnemy.AddComponent<EnemyMovement>();
        }
        movement.target = playerTransform;
        movement.stopDistance = 2.0f; // Adjust as necessary

        // Subscribe to the enemy reaching the target point if necessary
        movement.OnReachTarget += () =>
        {
            if (imagesOnEnemyReach.Length > index && imagesOnEnemyReach[index].Length > 0)
            {
                StartCoroutine(FadeInGroup(imagesOnEnemyReach[index]));
            }
        };

        // Wait until the enemy is destroyed
        Health enemyHealth = currentEnemy.GetComponent<Health>();
        while (enemyHealth != null && enemyHealth.IsAlive())
        {
            yield return null;
        }
    }

    IEnumerator FadeInGroup(GameObject[] group)
    {
        float elapsedTime = 0f;

        while (elapsedTime < fadeDuration)
        {
            elapsedTime += Time.deltaTime;
            SetGroupAlpha(group, Mathf.Clamp01(elapsedTime / fadeDuration));
            yield return null;
        }

        SetGroupAlpha(group, 1f);
    }

    IEnumerator FadeOutGroup(GameObject[] group)
    {
        float elapsedTime = 0f;

        while (elapsedTime < fadeDuration)
        {
            elapsedTime += Time.deltaTime;
            SetGroupAlpha(group, Mathf.Clamp01(1f - (elapsedTime / fadeDuration)));
            yield return null;
        }

        SetGroupAlpha(group, 0f);
    }

    void SetGroupAlpha(GameObject[] group, float alpha)
    {
        foreach (GameObject obj in group)
        {
            if (obj != null)
            {
                Image[] images = obj.GetComponentsInChildren<Image>();
                foreach (Image img in images)
                {
                    Color color = img.color;
                    color.a = alpha;
                    img.color = color;
                }
            }
        }
    }
}","using UnityEngine;
using UnityEngine.AI;
using System;

public class EnemyMovement : MonoBehaviour
{
    [Header("Target Settings")]
    public Transform target;                // Reference to the player's Transform
    public float stopDistance = 2.0f;       // Distance at which the enemy stops moving towards the target

    [Header("Animation Settings")]
    public Animator animator;               // Reference to the Animator

    [Header("Movement Settings")]
    public float chaseRange = 10f;          // Range within which the enemy starts chasing the player

    public Action OnReachTarget;            // Event to signal when the enemy reaches the target

    private NavMeshAgent agent;
    private SpriteRenderer spriteRenderer;
    private bool hasReachedTarget = false;  // Flag to ensure OnReachTarget is called only once

    protected virtual void Start()
    {
        // Get the NavMeshAgent component
        agent = GetComponent<NavMeshAgent>();
        if (agent == null)
        {
            Debug.LogError("NavMeshAgent missing on Enemy.");
            enabled = false;
            return;
        }

        // Get the SpriteRenderer component
        spriteRenderer = GetComponent<SpriteRenderer>();
        if (spriteRenderer == null)
        {
            Debug.LogError("SpriteRenderer missing on Enemy.");
            enabled = false;
            return;
        }

        // Get the Animator component if not assigned
        if (animator == null)
        {
            animator = GetComponent<Animator>();
        }

        // Check if the target has been assigned
        if (target == null)
        {
            Debug.LogError("Target not assigned in EnemyMovement.");
            enabled = false;
            return;
        }
    }

    protected virtual void Update()
    {
        if (target == null) return;

        float distance = Vector3.Distance(transform.position, target.position);

        if (distance <= chaseRange)
        {
            ChaseTarget();
            FlipSprite();

            // Check if reached the target
            if (!hasReachedTarget && agent.remainingDistance <= stopDistance && !agent.pathPending)
            {
                hasReachedTarget = true; // Prevents multiple triggers
                OnReachTarget?.Invoke();
            }
        }
        else
        {
            // Stop the enemy if the player is out of range
            agent.isStopped = true;
            if (animator != null)
            {
                animator.SetBool("running", false);
            }
        }
    }

    protected void ChaseTarget()
    {
        if (agent != null && target != null)
        {
            agent.isStopped = false;
            agent.SetDestination(target.position);

            if (animator != null)
            {
                animator.SetBool("running", true);
            }
        }
    }

    protected void FlipSprite()
    {
        Vector3 direction = agent.desiredVelocity;

        if (direction.x != 0)
        {
            spriteRenderer.flipX = direction.x < 0;
        }
    }
}","using UnityEngine;

public class Health : MonoBehaviour
{
    public int maxHealth = 100;
    private int currentHealth;

    void Start()
    {
        currentHealth = maxHealth;
    }

    public bool IsAlive()
    {
        return currentHealth > 0;
    }

    public void TakeDamage(int amount)
    {
        currentHealth -= amount;
        if (currentHealth <= 0)
        {
            Die();
        }
    }

    void Die()
    {
        // Potresti aggiungere qui effetti visivi o suoni
        Destroy(gameObject);
    }
}"