Play video seconds(frames) problem
Hi all. I have a intro video. this video length is 5 second. I convert the video to png frames(150 frame) I use this method to play frames:
public class Test {
public List<Sprite> _sprites = new List<Sprite>();
public Image _panel;
void Start(){
StartCoroutine(PlayIntro());
}
IEnumerator PlayIntro()
{
for(int i = 0; i<_sprites.count;i++)
{
_panel.sprite = _sprites[i];
yield return new WaitForSeconds(0.03f);
}
}
}
But this method is not good for mobile devices. In some devices, game crash before the scene opens. Is there any other way? Thanks
Answer by UnityCoach · Jan 03, 2017 at 11:47 AM
You can simply drag and drop your 150 frames in scene view in the editor, this will prompt you to save an animation file, name it, save it. It'll also create an AnimatorController and add an Animator component to your sprite object.
You can open the animation window (not animator), to set the framerate so that the animation is 5 seconds long.
Then, all you need is to trigger the animation playback. You can add a default state to you Animator Controller that does nothing, set it as default, then add a Trigger parameter, name "PlayIntro", then create a transition from default state to animated state with the Trigger condition, and in the code, simply do :
GetComponent<Animator>().SetTrigger ("PlayIntro");
Your answer
Follow this Question
Related Questions
load scene after video ended 2 Answers
videoPlayer Script Help Needed 0 Answers