- Home /
How I can change the sprite with resources.Load?
private float bildRate;
private float nextBild;
private int counter;
public int maxSpriteAnzahl;
public Image pic;
void Start()
{
bildRate = 0.0333333f;
pic = GetComponent<Image>();
}
void Update()
{
if (Time.time > nextBild)
{
nextBild = Time.time + bildRate;
counter++;
spriteAufrufen();
Debug.Log(counter);
}
if (counter >= maxSpriteAnzahl)
{
counter = 0;
}
}
void spriteAufrufen()
{
if (counter == 1)
{
Sprite sprit = Resources.Load("Resources/1") as Sprite;
pic.sprite = sprit;
}
if (counter == 2)
{
Sprite sprit = Resources.Load("Resources/2") as Sprite;
pic.sprite = sprit;
}
}
Comment
this code doesn't work I don't understand Please i need your help
Answer by OneCept-Games · Jan 02, 2018 at 08:01 PM
1: You do not need the Resources/, just 1 or 2, if your file is correctly placed in a Resource folder. 2: What type of file is your resource? If it is an Image file, like *.png, you cannot load it into a Brite object, but you have to assign it to the sprite's texture.
Your answer
Follow this Question
Related Questions
Make images fit in UI 0 Answers
Why is Sprite a null? 0 Answers
Possible to use sprite mesh for UI.Image GraphicRaycaster culling? 1 Answer
RGB UI Color Slider 2 Answers
How to match UI Image size with sprite size at runtime? 2 Answers