Tuesday, April 16, 2024
HomeSample Page

Sample Page Title

I wish to make a slide of pictures that change routinely by a timer with out urgent any button for instance each 5 seconds the picture adjustments to a different one. I’ve a script but it surely solely adjustments them when urgent a button I appeared in all places however I discovered no data about tips on how to do it with time as an alternative of sliding buttons.

that is the script I am utilizing now:

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

public class Slidescript : MonoBehaviour
    //All _slides within the venture, minus the _fadeSlide
    personal Checklist<Rework> _slides = default;

    //The panel that overlays all _slides and adjustments from clear to black
    personal Picture _fadeSlide = default;

    [Header("Config Values")]
    [SerializeField, Tooltip("The duration (in seconds) over which the fade slide will fade in / out")]
    personal float _fadeDuration = 0.75f;

    [SerializeField, Tooltip("All key codes that will move to the next slide if pressed")]
    personal KeyCode[] _nextSlideKeyCodes = {

    [SerializeField, Tooltip("All key codes that will move to the previous slide if pressed")]
    personal KeyCode[] _previousSlideKeyCodes = {

    //The slide we're at present viewing
    personal int _currentSlide = -1;

    // Whether or not the fade slide is at present fading
    personal bool _isTransitioning = false;

    personal void Begin()
        // Set our fade to black slide to black in order that the viewers cannot see the primary slide
        _fadeSlide.coloration = Colour.black;

    public void Replace()
        //Examine for arrow keys/house bar down so we are able to fade the fadePanel accordingly

    personal void ListenForInput()
        // Ignore enter if we're in the midst of a transition
        if (_isTransitioning)

        //If we strike the house bar or proper arrow key, proceed to the subsequent slide
        if (_nextSlideKeyCodes.Any(Enter.GetKeyDown))

        //If we strike the left arrow key, return to the earlier slide
        if (_previousSlideKeyCodes.Any(Enter.GetKeyDown))

        //If we strike the Esc key, give up the applying
        if (Enter.GetKeyDown(KeyCode.Escape))
            Utility.Give up();

    personal void NextSlide()
        //If we're on the final slide already..
        if (_currentSlide == _slides.Rely - 1)
            // Exit early

        //Increment the slide rely

        // Transition to the subsequent slide

    personal IEnumerator SlideTransition()
        // Mark our fading slide as at present fading
        _isTransitioning = true;

        // Fade to black
        yield return StartCoroutine(FadeToTargetColor(targetColor: Colour.black));

        // Set solely our present slide lively - and all others inactive
        _slides.ForEach(slide => slide.gameObject.SetActive(_slides.IndexOf(slide) == _currentSlide));

        // Fade to clear
        yield return StartCoroutine(FadeToTargetColor(targetColor: Colour.clear));

        // Mark our fading slide as not fading
        _isTransitioning = false;

    personal void PreviousSlide()
        //If the present slide is the very first slide, ignore the remainder of this methodology
        if (_currentSlide == 0)

        //Decrement the present slide

        // Transition to the earlier slide

    personal IEnumerator FadeToTargetColor(Colour targetColor)
        // The overall quantity of seconds that has elapsed because the begin of our lerp sequence
        float elapsedTime = 0.0f;

        // The colour of our fade panel in the beginning of the lerp sequence
        Colour startColor = _fadeSlide.coloration;

        // Whereas we've not reached the top of the lerp sequence..
        whereas (elapsedTime < _fadeDuration)
            // Enhance our elapsed time
            elapsedTime += Time.deltaTime;

            // Carry out a lerp to our goal coloration
            _fadeSlide.coloration = Colour.Lerp(startColor, targetColor, elapsedTime / _fadeDuration);

            // Await the subsequent body
            yield return null;



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments