Questions about building a simple 2d image carousel
Hello,
I'm a beginner with Unity and I'm starting my first project to learn some basic stuff.
I want to build an image carousel from scratch with the idea of customizing it later. At the moment, I would like it to show only one image at a time and I would like to simply replace it in response to an action.
What I've tried so far is to add a Sprite object to my scene to which I added my script component.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Game : MonoBehaviour {
public Sprite[] images = new Sprite[4];
SpriteRenderer sr;
void Start () {
sr = GetComponent<SpriteRenderer>();
sr.sprite = images[2];
}
}
At the moment I'm not really thinking about the interaction, I'm just trying to understand how to correctly display a single image.
In unity I set the initial sprite to the desired size, I initialize the image array with a couple of images and when I run the code I see the sprite changing. The problem is that the new sprite appears too big.
What am I doing wrong?
Also, before doing this, I had a look at other projects, but I'm still not sure whether is best to use Sprites, ui.Images or Texture2D for this case.
Thanks in advance for the help!