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 Dee Va · Dec 24, 2012 at 08:07 AM · textureruntimewaitforseconds

Switching From one texture to another

hi, In my game,I want to make a intro scene beofore the game start's...here's my problem how can i change texture form one to another in runtime.. i made a script,am a modeler who don't know scripting :/

here's my script,can anyone please correct this :-

 var anim1 : Texture;
 var anim2 : Texture;
 var anim3 : Texture;
 var anim4 : Texture;
 
 function Start () {   
 renderer.material.mainTexture = anim1;
 yield WaitForSeconds(2);
  renderer.material.mainTexture = anim2;
  yield WaitForSeconds(2);
   renderer.material.mainTexture = anim3;
  yield WaitForSeconds(2);
  renderer.material.mainTexture = anim4;
  yield WaitForSeconds(2);
  
  Application.LoadLevel(2);
 
 }

thank you :)

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
3
Best Answer

Answer by Eric5h5 · Dec 24, 2012 at 09:38 AM

Your script works fine as-is, but it could be written as:

 var textures : Texture[];
 var delayTime = 2.0;
 
 function Start () {
     for (var i = 0; i < textures.Length; i++) {
         renderer.material.mainTexture = textures[i];
         yield WaitForSeconds (delayTime);
     }
     Application.LoadLevel (2);
 }
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
avatar image
1

Answer by Griffo · Dec 24, 2012 at 08:20 AM

Try this, drop you object to change texture on into myCharacter in the inspector.

 var myCharacter:Transform;
 
 var anim1 : Texture;
 var anim2 : Texture;
 var anim3 : Texture;
 var anim4 : Texture;
 
 function Start () {
 
     ChangeTexture();
 }
 
 function Update(){
 
 }
 
 function ChangeTexture(){
 
 myCharacter.renderer.material.mainTexture = anim1;
 yield WaitForSeconds(2);
 myCharacter.renderer.material.mainTexture = anim2;
 yield WaitForSeconds(2);
 myCharacter.renderer.material.mainTexture = anim3;
 yield WaitForSeconds(2);
 myCharacter.renderer.material.mainTexture = anim4;
 yield WaitForSeconds(2);
 
  Application.LoadLevel("Level Two");
 
 }
Comment
Add comment · Show 2 · 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 Dee Va · Dec 24, 2012 at 08:33 AM 0
Share

only appearing anim1...it's not changing to anim2 :/

avatar image Eric5h5 · Dec 24, 2012 at 09:33 AM 0
Share

Start can be a coroutine, and you don't need (and shouldn't have) an empty Update function, since it creates unnecessary overhead.

avatar image
1

Answer by Maulik2208 · Dec 24, 2012 at 08:31 AM

 using UnityEngine;
 using System.Collections;
 
 public class NewBehaviourScript : MonoBehaviour 
 {
     public Texture2D anim1;//This is your textures have to assign in inspector
     public Texture2D anim2;
     public Texture2D anim3;
     public Texture2D anim4;
     public GameObject Player;//this is the game object you have to assign in
                     // inspector....you can change the name as per your need
 
        // Use this for initialization
     void Start ()
     {
        StartCoroutine ("ChangeTexture");
     }
 
    IEnumerator ChangeTexture() 
 {
         Player.renderer.material.mainTexture = anim1;
         yield return new WaitForSeconds(5);
         Player.renderer.material.mainTexture = anim2;
         yield return new WaitForSeconds(5);
         Player.renderer.material.mainTexture = anim3;
         yield return new WaitForSeconds(5);
         Player.renderer.material.mainTexture = anim4;
         yield return new WaitForSeconds(5);
 
 
 
     Application.LoadLevel(2);
 
 }
 }

 

This is the script for C# which is doing well......here gameobject should be replace with the name of your gameobject.......Cheers......Enjoy.....If found useful then don't forget to mark.....

Comment
Add comment · Show 10 · 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 Dee Va · Dec 24, 2012 at 08:39 AM 0
Share

how to add this in C#

var anim1 : Texture; var anim2 : Texture; var anim3 : Texture; var anim4 : Texture;

sorry, i have no idea about C#

avatar image Maulik2208 · Dec 24, 2012 at 08:41 AM 1
Share

Wait i am giving you a complete script

avatar image Dee Va · Dec 24, 2012 at 08:43 AM 0
Share

thank you :D

avatar image Maulik2208 · Dec 24, 2012 at 08:50 AM 0
Share

Check the script it's modified

avatar image Eric5h5 · Dec 24, 2012 at 10:54 AM 1
Share

I've seen it create a lot of confusion with people who are new to program$$anonymous$$g, since they're having a hard enough time with one language. So it would generally be better to hold off answering in a different language, except as a last resort if the question has gone unanswered for a while.

Show more comments

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

11 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

Related Questions

How to change the color of predefine portion of the texture? 1 Answer

Changing terrain texture at runtime 1 Answer

Mesh Creator (editor script) At Runtime 1 Answer

Assigning Textures to Terrain at Runtime 2 Answers

Is it possible to save loaded textures and reuse after close app? 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