Hi guys I have the following issue:
I have an array called Cases which has 8 values and each one of them are instantiated through this piece of code:
Instantiate(Cases[UnityEngine.Random.Range(0, 7)], transform.position, this.transform.rotation);
Then, I have another array called Images which has 8 sprites. I’ve created this one, because I got a canvas that has an image component attached to it, and I’d like to put the sprites in this image component, but in the following way:
For instance, if the case number 1 is instantiated, so I wanna take this value from the array Cases and use it in the script that I have the array called Images, in order to use the sprite number 1.
How could I do it?
public Image canvasImageComponent;//drag and drop from inside the editor
public void SetImage(int index)
{
int randomValue = UnityEngine.Random.Range(0, 7);
Instantiate(randomValue, transform.position, this.transform.rotation);
canvasImageComponent.sprite = Images[randomValue];
}