how to play a slideshow of images?

i want to show 3/4 jpegs to create a slideshow. I have the following code:

using UnityEngine;
using System.Collections;

public class SlideShow : MonoBehaviour
{
	public Texture2D[] slides = new Texture2D[9];
	public float changeTime = 10.0f;
	private int currentSlide = 0;
	private float timeSinceLast = 1.0f;
	
	void Start()
	{
		guiTexture.texture = slides[currentSlide];
		guiTexture.pixelInset = new Rect(-slides[currentSlide].width/20, -slides[currentSlide].height/20, slides[currentSlide].width, slides[currentSlide].height);
		currentSlide++;
	}
	
	void Update()
	{
		if(timeSinceLast > changeTime &&  currentSlide < slides.Length)
		{
			guiTexture.texture = slides[currentSlide];
			guiTexture.pixelInset = new Rect(-slides[currentSlide].width/20, -slides[currentSlide].height/20, slides[currentSlide].width, slides[currentSlide].height);
			timeSinceLast = 0.0f;
			currentSlide++;
		}
		timeSinceLast += Time.deltaTime;
	}
}

but pictures are offset and not to scale. any help please?

Do remember that the origin for sprites/GameObjects in Unity is default in the center, which may explain why you have offset images.

Secondly, the camera viewport does not display in terms of pixels, but in unity units. Therefore when viewed in Game mode, the images will be scaled with the view port, therefore will not be the right scale.

There are two issues here. One of position and one of scale. GUITexture objects live in viewport space. Viewport space starts at (0,0) in the lower left corner and goes to (1,1) in the upper right. So to get your images centered on the screen do:

  • Set the position in the transform to (0.5, 0.5, 0.0).
  • Calculate the pixel inset by dividing by 2.0, not 20.0.

I just tested your code with these changes, and the image was in the center of the screen.

The second issue is scale. I believe there is a bug in Unity 4.6 (or at least something I don’t understand). I don’t have a previous version of Unity installed to verify, but I believe previous versions, a localScale of (1,1,1) would produce a ‘pixel perfect’ image (given the pixel inset setup to match the image). But using 4.6, the image is too large. It appears that (0.1, 0.1, 0.1) is close to correct, but you’ll want to check into the situation and verify with a release version of 4.6.

You can use IEnumerator or use Update(). This is the simple code that I am using. You can modify the code as per you requirement. This is a sample code just to get the idea. This is the simplest method that I used

public class SlideImage
{
    public Transform currentPlayer;

    IEnumerator SlideImagesLeft()
    {
        while (currentPlayer.position.x > targetPosition.x)
        {            
            currentPlayer.position = Vector3.MoveTowards(currentPlayer.position, targetPosition, 1000f * Time.deltaTime);            
            yield return null;            
        }
    }
}

If you are using Update while loop must be removed just currentPlayer.position = Vector3.MoveTowards(currentPlayer.position, targetPosition, 1000f * Time.deltaTime); is important in Update(). Don’t forget to attach Image or any Rect Transform to the currentPlayer in the Inspector