#Cinemachine Camera blend do not work via code

1 messages · Page 1 of 1 (latest)

jagged gyro
#

Hi guys, here is my code :

...

public class TimelineForestController : MonoBehaviour
{
    [Header("Liste des Cinemachine Cameras dans l'ordre")]
    public List<CinemachineCamera> virtualCameras;


    private int currentIndex = 0;
    /// <summary>
    /// Change la caméra dans le sens indiqué (1 = suivante, -1 = précédente)
    /// </summary>
    public void ChangeCamera(int direction)
    {
        if(direction == 0)
        { 
            //INITIALISATION CALL
            // Met toutes les caméras avec une priorité basse
            for (int i = 0; i < virtualCameras.Count; i++)
            {

                virtualCameras[i].Priority = 0;
                virtualCameras[i].enabled = true;
                virtualCameras[i].gameObject.SetActive(true);
            }

            // Active la première cam
            if (virtualCameras.Count > 0)
                virtualCameras[0].Priority = 10;
        }
        currentIndex += direction;

        if (currentIndex >= virtualCameras.Count)
            currentIndex = 0;
        else if (currentIndex < 0)
            currentIndex = virtualCameras.Count - 1;

        ActivateCamera(currentIndex);
    }

    private void ActivateCamera(int index)
    {
        for (int i = 0; i < virtualCameras.Count; i++)
        {
            // La nouvelle caméra prend une priorité haute
            virtualCameras[i].Priority = (i == index) ? 10 : 0;
        }
    }

    // ===========================
    // Commandes contextuelles (clic-droit dans l'Inspector)
    // ===========================
    [ContextMenu("Camera suivante (+1)")]
    private void ContextNextCamera() => ChangeCamera(+1);

    [ContextMenu("Camera précédente (-1)")]
    private void ContextPreviousCamera() => ChangeCamera(-1);
}

I don't know why, but via, the code, the blending between my cameras is not working.
But, when i do it manually via the inspector (by editing the priority), the blending is working.... Do you know why ?

jagged gyro
#

i'm trying to add a button in a canvas to test

last bluff