Search Unity

Issue with Texture Change

Discussion in 'Scripting' started by Seppi, Mar 24, 2013.

  1. Seppi

    Seppi

    Joined:
    Nov 10, 2012
    Posts:
    162
    Code (csharp):
    1. var textureOne : Texture2D;
    2. var textureTwo : Texture2D;
    3.  
    4. InvokeRepeating("Change", 0, 1);
    5.  
    6. function Start () {
    7. renderer.material.mainTexture = textureOne;
    8. }
    9.  
    10. function Change () {
    11. if(renderer.material.mainTexture == textureOne){
    12.     renderer.material.mainTexture = textureTwo;
    13. }
    14.  
    15. if(renderer.material.mainTexture == textureTwo){
    16.     renderer.material.mainTexture = textureOne;
    17. }
    18. }
    No errors or anything, the texture just doesnt change.

    Can someone point me in the right direction? I just need the texture to change every "x" seconds.
     
  2. scrawk

    scrawk

    Joined:
    Nov 22, 2012
    Posts:
    804
    Hi, you will need to use a else if statement for second if. You are applying texture two the reapplying texture one again.


    Code (csharp):
    1. if(renderer.material.mainTexture == textureOne)
    2.     renderer.material.mainTexture = textureTwo;
    3. else if(renderer.material.mainTexture == textureTwo)
    4.     renderer.material.mainTexture = textureOne;