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 all over the place however I discovered no data about do it with time as a substitute 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 mission, minus the _fadeSlide
[SerializeField]
non-public Listing<Rework> _slides = default;
//The panel that overlays all _slides and adjustments from clear to black
[SerializeField]
non-public Picture _fadeSlide = default;
[Header("Config Values")]
[SerializeField, Tooltip("The duration (in seconds) over which the fade slide will fade in / out")]
non-public float _fadeDuration = 0.75f;
[SerializeField, Tooltip("All key codes that will move to the next slide if pressed")]
non-public KeyCode[] _nextSlideKeyCodes = {
KeyCode.D,
KeyCode.RightArrow,
KeyCode.Area
};
[SerializeField, Tooltip("All key codes that will move to the previous slide if pressed")]
non-public KeyCode[] _previousSlideKeyCodes = {
KeyCode.A,
KeyCode.LeftArrow,
};
//The slide we're presently viewing
non-public int _currentSlide = -1;
// Whether or not the fade slide is presently fading
non-public bool _isTransitioning = false;
non-public void Begin()
{
// Set our fade to black slide to black in order that the viewers cannot see the primary slide
_fadeSlide.colour = Shade.black;
}
public void Replace()
{
//Test for arrow keys/area bar down so we will fade the fadePanel accordingly
ListenForInput();
}
non-public void ListenForInput()
{
// Ignore enter if we're in the midst of a transition
if (_isTransitioning)
{
return;
}
//If we strike the area bar or proper arrow key, proceed to the subsequent slide
if (_nextSlideKeyCodes.Any(Enter.GetKeyDown))
{
NextSlide();
}
//If we strike the left arrow key, return to the earlier slide
if (_previousSlideKeyCodes.Any(Enter.GetKeyDown))
{
PreviousSlide();
}
//If we strike the Esc key, give up the appliance
if (Enter.GetKeyDown(KeyCode.Escape))
{
Software.Give up();
}
}
non-public void NextSlide()
{
//If we're on the final slide already..
if (_currentSlide == _slides.Rely - 1)
{
// Exit early
return;
}
//Increment the slide rely
_currentSlide++;
// Transition to the subsequent slide
StartCoroutine(SlideTransition());
}
non-public IEnumerator SlideTransition()
{
// Mark our fading slide as presently fading
_isTransitioning = true;
// Fade to black
yield return StartCoroutine(FadeToTargetColor(targetColor: Shade.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: Shade.clear));
// Mark our fading slide as not fading
_isTransitioning = false;
}
non-public void PreviousSlide()
{
//If the present slide is the very first slide, ignore the remainder of this technique
if (_currentSlide == 0)
{
return;
}
//Decrement the present slide
_currentSlide--;
// Transition to the earlier slide
StartCoroutine(SlideTransition());
}
non-public IEnumerator FadeToTargetColor(Shade targetColor)
{
// The entire quantity of seconds that has elapsed because the begin of our lerp sequence
float elapsedTime = 0.0f;
// The colour of our fade panel firstly of the lerp sequence
Shade startColor = _fadeSlide.colour;
// 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 colour
_fadeSlide.colour = Shade.Lerp(startColor, targetColor, elapsedTime / _fadeDuration);
// Await the subsequent body
yield return null;
}
}
}