11.9 C
New York
Tuesday, October 14, 2025

unity – How would I make a “slideshow” cutscene?


I am making a 2D recreation utilizing Unity and I wish to implement cutscenes that change over at sure traces.

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
utilizing UnityEngine.UI;

public class CgChanger : MonoBehaviour
{
   public Picture imageToChange; // Reference to the UI Picture element
    public Sprite[] sprites; // Array of sprites to cycle by means of`

    personal int currentSpriteIndex = 0;

    void Begin()
    {
        if (imageToChange == null || sprites == null || sprites.Size < 6)
        {
            Debug.LogError("ImageToChange or Sprites usually are not assigned or Sprites array has fewer than 6 components.");
            return;
        }

        // Initialize with the primary sprite
        imageToChange.sprite = sprites[currentSpriteIndex];
    }

    void Replace()
    {
        // Examine if the left mouse button is pressed
        if (Enter.GetMouseButtonDown(0))
        {
            // Transfer to the subsequent sprite within the array
            currentSpriteIndex++;

            // Guarantee we don't exceed the array bounds
            if (currentSpriteIndex >= sprites.Size)
            {
                currentSpriteIndex = 0; // Reset to the primary sprite if the top is reached
            }

            // Change the picture sprite to the subsequent one within the array
            imageToChange.sprite = sprites[currentSpriteIndex];
        }
    }
}

That is the code I’ve at present, however it’s flawed and I am undecided the way to repair it. I do not need it to vary when the individual clicks down on the mouse like it’s with the textual content, and the way it’s with the photographs at present. That messes up the pacing if somebody clicks greater than as soon as per line. How would I’m going about altering this?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles