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
1
Question by AitorMihashi · Jan 09, 2014 at 03:34 PM · texturechangeyielddelaymario

How to change a Texture with a Delay

I am trying to do a copy of the Mario with another character. The problem happens when the character have velocity.x == 0 change between 2 textures but goes very fast. I tried using "yield WaitForSeconds(1.5)" but doesn´t work.

Thanks to all of you.

I leave the code here:

 function Update () 
 {

 velocity = Vector3(Input.GetAxis("Horizontal"), 0, 0);
 
 if(velocity.x == 0)
 {
     StopCoroutine("MovIdle");
     StartCoroutine("MovIdle");
 }
 
 if(velocity.x > 0)
 {
     Caminar();
 }

}

var imagenes : Texture[];

// This is the first option that i used

 function Animacion()
 {
     for(var img in imagenes)
     {
         renderer.material.SetTexture("_MainTex", img);
         yield WaitForSeconds(retraso);
     }
 }

// This is the second option that i used

 function MovIdle()
 {
     if(contador == 0)
     {
     yield WaitForSeconds(retraso);
         renderer.material.SetTexture("_MainTex", imagenQuieto1);
         contador++;
     }
     else if(contador == 1)
     {
     yield WaitForSeconds(retraso);
         renderer.material.SetTexture("_MainTex", imagenQuieto2);
         contador = 0;
     }
 }

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by edcarlo · Jan 10, 2014 at 01:17 AM

You dont need to use forloop for 2 textures.

 public var t1:Texture;
 public var t2:Texture;
 
 function ChangeTex(){
     yield WaitForSeconds(1.5);
     renderer.material.SetTexture("_MainTex",t1); //renderer.material.mainTexture = t1;
 
     yield WaitForSeconds(1.5);
     renderer.material.SetTexture("_MainTex",t2); //renderer.material.mainTexture = t2;
 }
 
 //StartCoroutine("ChangeTex");

But, if you want multiple textures:

 public var texs : Textures[];
 
 function ChangeTexs()
 {
     var i : int = 0;
     var l : int = texs.length;
 
     while(i < l)
     {
         renderer.material.SetTexture("_MainTex", texs[i])
         i++;
         yield WaitForSeconds(1.5);
     }
 }
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

19 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

Related Questions

Delay Jump 1 Answer

Forced player reset not being delayed 1 Answer

Delay my Scene for few seconds, not sure what wrong 2 Answers

Assigning UV Map to model at runtime 0 Answers

How to change texture on parts of terrain 3 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