0
  • i have a scene in which after a particular time the slide show of images should start.

  • i have created the texture array and loaded the images to array in inspector.

  • now i need to slide each image after every two seconds.

  • this is the code i have done but it is error

    public Texture[] Images;
    
    void ChangeImage()
    

    {

    for(int i=1;i<Imagez.Length;i++)
    {
    
        print (Imagez [i].ToString());
        Imag =Imagez [i];
    
    }
    
    
    }
    

i try to load each image from the array, but i know that its not the proper way..can any one please help

Martin j
  • 511
  • 1
  • 9
  • 31
  • here's an absolute-beginner's guide to making a Canvas and starting with UI, good luck! http://stackoverflow.com/a/36268018/294884 – Fattie Nov 28 '16 at 11:47

1 Answers1

2

Add a scroll rect then add a panel for container and make that panel the scroll rect to control.

Then the container gets a Horizontal/VerticalLayoutGroup. Add all of your images and set the container size so they show properly.

Run the game, you should be able to scroll them appropriately (make sure you constrain the movement hor/vert so it moves correctly).

private int currentIndex = 0;
[SerializeField] private float imageSize;
[SerializeField] private RectTransform panel;
[SerializeField] private float frequency;
void Start()
{
    InvokeRepeating("IncreaseCurrentIndex", frequency,frequency);
}
private void IncreaseCurrentIndex()
{
    if(++this.currentIndex >= this.imageCount){ this.currentIndex = 0; }
}

void MoveToNextItem()
{
    float targetX = (float)this.currentIndex * this.imageSize; 
    Vector2 delta = this.panel.anchoredPosition;
    delta.x = Mathf.MoveTowards(delta.x, targetX, Time.deltaTime * speed);
    this.panel.anchoredPosition = delta;
}

First you give the size of the image in the inspector. The panel is the container for all the images. I guess the rest is self explanatory.

The code is as simple as possible, it could benefit more flexibility but at least it should go as is.

NOTE: This is meant to be for horizontal scrolling. You would change the x for y in the update for vertical scrolling. Also, it uses Mathf.MoveTowards, you could use lerp instead of the velocity of scroll rect.

Everts
  • 10,408
  • 2
  • 34
  • 45
  • thank u soo much ...but i am a beginner and i really dont know what to do that u told in answer – Martin j Nov 28 '16 at 09:18
  • i have edited the que ..imag is a image i created in the scene how to load the image arrays into that image – Martin j Nov 28 '16 at 09:20