Search Unity

Slideshow background behind GUI??

Discussion in 'Immediate Mode GUI (IMGUI)' started by mikesgames, Sep 13, 2010.

  1. mikesgames

    mikesgames

    Joined:
    Apr 16, 2010
    Posts:
    1,071
    ANyone know how to make a slideshow style background, that shows several images, one after another at regular intervals.

    It has to appear behind the GUI.

    Thanks!
     
  2. CorruptedHeart

    CorruptedHeart

    Joined:
    May 4, 2010
    Posts:
    379
    Just attach this to a game object with a guiTexture attached and set the textures in the array:
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class SlideShow : MonoBehaviour
    5. {
    6.     public Texture2D[] slides = new Texture2D[9];
    7.     public float changeTime = 10.0f;
    8.     private int currentSlide = 0;
    9.     private float timeSinceLast = 1.0f;
    10.    
    11.     void Start()
    12.     {
    13.         guiTexture.texture = slides[currentSlide];
    14.         guiTexture.pixelInset = new Rect(-slides[currentSlide].width/2, -slides[currentSlide].height/2, slides[currentSlide].width, slides[currentSlide].height);
    15.         currentSlide++;
    16.     }
    17.  
    18.     void Update()
    19.     {
    20.         if(timeSinceLast > changeTime  currentSlide < slides.Length)
    21.         {
    22.             guiTexture.texture = slides[currentSlide];
    23.             guiTexture.pixelInset = new Rect(-slides[currentSlide].width/2, -slides[currentSlide].height/2, slides[currentSlide].width, slides[currentSlide].height);
    24.             timeSinceLast = 0.0f;
    25.             currentSlide++;
    26.         }
    27.         timeSinceLast += Time.deltaTime;
    28.     }
    29. }
    EDIT: Added Start() because a texture wasn't showing up straight away
     
  3. mikesgames

    mikesgames

    Joined:
    Apr 16, 2010
    Posts:
    1,071
    Thanks dude!
     
  4. CorruptedHeart

    CorruptedHeart

    Joined:
    May 4, 2010
    Posts:
    379
    I have since then also added a bit of code that will make it loop if you so wish:
    Code (csharp):
    1. // -----------------------
    2.         if(currentSlide == slides.Length)
    3.         {
    4.             currentSlide = 0;
    5.         }
    6.         // ------------------------
    Just add that at the end of the Update() method
     
  5. mikesgames

    mikesgames

    Joined:
    Apr 16, 2010
    Posts:
    1,071
    sweet. thanks so much dude
     
  6. CorruptedHeart

    CorruptedHeart

    Joined:
    May 4, 2010
    Posts:
    379
    No problem, it was a nice little challenge.
     
  7. Luis1604

    Luis1604

    Joined:
    Dec 15, 2011
    Posts:
    7
    Dear Colleagues,

    I need this script but with a more functionality, it is little, i got 1452 photos, all named from 0 to 1451, so I need when I put these pictures in the GUI Texture with the script he put in ordem.Example:

    Photo 0 in element 0
    Photo 1 in element 1

    When I played my 1451 photos he ordered them randomly.Since I am a beginner in programming with C # I could not use a quicksort algorithm.Either to know if I can use a quicksort for it.

    Greetings,
    Luis1604
     
    Last edited: Jan 25, 2012
  8. Luis1604

    Luis1604

    Joined:
    Dec 15, 2011
    Posts:
    7
    Nobody?
    Forever Alone...
     
  9. roman_arch

    roman_arch

    Joined:
    Jan 29, 2014
    Posts:
    2
    hi CorruptedHeart...first of all, many many thanks for the script. it worked fine. but a bit problem like:
    >i have 10 images
    >5 of them are in 1000X500 px and
    >rest 5 are in 500X1000 px
    while showing the 1st 5 are okay in showing. but the rest 5 are stressed to 1000X500.
    how can i tell the script to call the image px size and shows as they are.
    and if i want to add a fade in-fade out effect what should i do.
    pls help...thanks a lot in advance.
     
  10. FreightTrainX2

    FreightTrainX2

    Joined:
    Dec 10, 2015
    Posts:
    1
    I tried this but the image I wanted still popped up on the front of the screen. I'm trying to place it on a grid instead.
     
  11. tloarie

    tloarie

    Joined:
    Jul 3, 2017
    Posts:
    1
    I'm looking to add a slideshow like this to my project, can someone please explain how to add the array?