Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 Wesley21spelde · Jan 25, 2014 at 11:21 AM · materialscritping

Computer screen animation by texture

hey guys i ve been looking everywhere for my solution but i cant find it like this. would you help me with a script. i have a 3d model of a computer screen with one texture added to it. i have 10 other textures. i want to change the textures lets say every 0.1 seconds like 12345678910 so the computer screen animates thanks guys

Comment
Add comment · Show 1
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 Invertex · Jan 25, 2014 at 11:44 AM 0
Share

How big are the textures, resolution wise? If they are small enough to all fit on one texture less than 8192x8192, then you could just use the Sprite Renderer system to create a looped animation.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Nirav-Madhani · Mar 27, 2015 at 06:03 AM

Create a C script named ImageFromDirectory and add following code

 using UnityEngine;
     using System.Collections;
     
     public class ImageFromDirectory : MonoBehaviour
     {
         //A texture object that will output the animation
         private Texture texture;
         //With this Material object, a reference to the game object Material can be stored
         private Material goMaterial;
         //An integer to advance frames
         private int frameCounter = 0;
         
         //A string that holds the name of the folder which contains the image sequence
         public string folderName;
         //The name of the image sequence
         public string imageSequenceName;
         //The number of frames the animation has
         public int numberOfFrames;
         
         //The base name of the files of the sequence
         private string baseName;
         
         void Awake()
         {
             //Get a reference to the Material of the game object this script is attached to
             this.goMaterial = this.renderer.material;
             //With the folder name and the sequence name, get the full path of the images (without the numbers)
             this.baseName = this.folderName + "/" + this.imageSequenceName;
         }
         
         void Start ()
         {
             //set the initial frame as the first texture. Load it from the first image on the folder
             texture = (Texture)Resources.Load(baseName + "00000", typeof(Texture));
         }
         
         void Update ()
         {
             //Start the 'PlayLoop' method as a coroutine with a 0.04 delay
             StartCoroutine("PlayLoop", 0.04f);
             //Set the material's texture to the current value of the frameCounter variable
             goMaterial.mainTexture = this.texture;
         }
         
         //The following methods return a IEnumerator so they can be yielded:
         //A method to play the animation in a loop
         IEnumerator PlayLoop(float delay)
         {
             //wait for the time defined at the delay parameter
             yield return new WaitForSeconds(delay);  
             
             //advance one frame
             frameCounter = (++frameCounter)%numberOfFrames;
             
             //load the current frame
             this.texture = (Texture)Resources.Load(baseName + frameCounter.ToString("D5"), typeof(Texture));
             
             //Stop this coroutine
             StopCoroutine("PlayLoop");
         }
         
         //A method to play the animation just once
         IEnumerator Play(float delay)
         {
             //wait for the time defined at the delay parameter
             yield return new WaitForSeconds(delay);  
             
             //if it isn't the last frame
             if(frameCounter < numberOfFrames-1)
             {
                 //Advance one frame
                 ++frameCounter;
                 
                 //load the current frame
                 this.texture = (Texture)Resources.Load(baseName + frameCounter.ToString("D5"), typeof(Texture));
             }
             
             //Stop this coroutine
             StopCoroutine("Play");
         }
     }
 

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.

Follow this Question

Answers Answers and Comments

20 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 avatar image avatar image avatar image

Related Questions

Material doesn't have a color property '_Color' 4 Answers

Changing two different objects renderer colour 1 Answer

Why are Textures applied to multiple materials script. 0 Answers

Set base color of a specific material 1 Answer

Change material of all the children 2 Answers


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