• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by PhoenixBlackReal · Sep 10, 2013 at 05:26 PM · array

The image sequence of an array is moving too fast

I've made a c# script which loads an image sequence thus producing an effect of a video being played.

The video is moving too fast. No matter what adjustments are done to the code, it doesn't react.

using UnityEngine; using System.Collections;

public class animation : MonoBehaviour {

 public Texture2D[] images;
 private int i=0;
 public float currentImageTime = 0f;
 public AudioClip videoSound;
 public bool videoIsPlaying = false;
 public float regulateSpeed = 0f;
 
 void Start()
 {
     if(videoIsPlaying==true)
     audio.PlayOneShot(videoSound);
 }

 void Update ()
 {
     currentImageTime += Time.deltaTime*10f;
     if(i<images.Length)
     {
     ChangeImage();
     videoIsPlaying = true;
     }
     else
     {
     videoIsPlaying = false;
     }
 }
 
 void OnGUI() 
 {
     i++;
     GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height), images[i]); 
     
 }
 
 void ChangeImage()
 {
     if(currentImageTime >= regulateSpeed)
     {     
         OnGUI ();
         currentImageTime = 0f;
     }
     else{}
 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by FrimaMickD · Sep 10, 2013 at 06:01 PM

The OnGUI() functions is called at each frame by Unity itself, it's not a function you should call yourself. You should not call it in ChangeImage() its wrong code. Instead do i++ in the ChangeImage.

 void ChangeImage()

{

   if(currentImageTime >= regulateSpeed)
   {

      i++;

      currentImageTime -= regulateSpeed;

   }

}

And of course remove the i++ from OnGUI.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image PhoenixBlackReal · Sep 11, 2013 at 07:52 PM 0
Share

This sort of works, but there's another problem. I can make it very slow and speed it up to a point - but there's that point where the speed is too fast and constant. I cannot have a single speed chosen by me. Hos is this to be fixed?

avatar image FrimaMickD · Sep 12, 2013 at 12:32 PM 0
Share

This is weird :

 currentImageTime += Time.deltaTime*10f;

Why the multiplication by 10? Remove that, you should have a better control over this...But still, why are you trying to do this, why not play a video directly?

avatar image PhoenixBlackReal · Sep 13, 2013 at 12:03 PM 0
Share

I fixed it, about the video - you need to buy the pro version. I'm working without money. Thanks for the help :)

avatar image
0

Answer by eddyzy · Sep 10, 2013 at 06:06 PM

there`s a function called WaitForSeconds

http://docs.unity3d.com/Documentation/ScriptReference/WaitForSeconds.html

so load your i image and after that use this function to wait for ,let`s say 1 sec.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image FrimaMickD · Sep 10, 2013 at 06:20 PM 0
Share

That's not his problem...

avatar image
0

Answer by PhoenixBlackReal · Sep 14, 2013 at 11:41 AM

Also, for many peeps who have a similar problem, find this hoping for an answer and then only see "I fixed it", but not the actual answer - the code is fine, once you divide the videoTime from imageAmount, thus giving how much time each frame has t be shown. The problem is - it's not the exact amount of frames as in the video, so a bit of fluent sync will be lost. If it doesn't sync no matter how many times you've played with the numbers - change amount of the frames, etc.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Instantiate specific object from "FindGameObjectsWithTag" Array 0 Answers

Make an Array of Particles emit at the same time 1 Answer

Play sound from an array, not random, and only once 3 Answers

Array element to variable 1 Answer

Enabled all gameobjects in array 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges