- Home /
my picture load another pict too fast
hi , i currently have my project and a little stuck at some point , there i want to load 2 pict at the panel , i set up it changes every 2f , but everytime when its come to pict 2 its just go through the pict 1 again.
this my code below , please help sir , thankyou
uploadimage.sprite = Resources.Load(filepath + "helmimg");
timer -= Time.deltaTime;
if (timer <= 0f)
{
if (uploadimage.sprite == Resources.Load<Sprite>(filepath + "helmimg"))
{
uploadimage.sprite = Resources.Load<Sprite>(filepath + "helmimg2");
timer = delay;
break;
}
if (uploadimage.sprite == Resources.Load<Sprite>(filepath + "helmimg2"))
{
uploadimage.sprite = Resources.Load<Sprite>(filepath + "helmimg");
timer = delay;
break;
}
}
Answer by GamitusLabs · Nov 12, 2018 at 04:15 AM
A few things:
Why are you are loading the sprite from file every time? Are you working within a super small/limited memory footprint?
break is used to exit a loop and switch blocks, so it won't exit your nested if statements
Recommendations:
If you are not under a memory crunch... load your resources in at load time. In your particular scenario something like an array with an integer for keeping track of the current sprite index would work nicely.
Following recommendation 1, you could then do something like...
Pseudo code
if (current sprite == 1)
current sprite = 2
else
current sprite = 1
set delay timer
EDIT: Unity... the code blocking functionality on these forums is a bit finicky and could use some work
thankyou sir for replaying , but i still not understand about the code, honestly i have two scripts, defaulthandler & the Target data. but when i put uploadimage.sprite = Resources.Load(filepath + "helmimg");
and another at target data is working , but when i trying to move it to just one script its not working at all , its just moving to fast . and im trying your code , i cant set my delay timer..
Your answer
![](https://koobas.hobune.stream/wayback/20220612181955im_/https://answers.unity.com/themes/thub/images/avi.jpg)