Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Animated texture for projector?

Discussion in 'iOS and tvOS' started by VIC20, May 25, 2009.

  1. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,682
    I found this one in another Thread but it does not work in unity iphone.

    Code (csharp):
    1. var newTexture : Texture;
    2.  
    3. function Start ()
    4. {
    5.    SwapTexture (newTexture);
    6. }
    7.  
    8. function SwapTexture (swap : Texture)
    9. {
    10.    var projector = GetComponent (Projector);
    11.    projector.material.SetTexture ("_ShadowTex", swap);
    12. }
    Any idea how to make a animated projection on the iphone?
     
  2. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,682
    got it by changing a script from the unity reference:

    Code (csharp):
    1. #pragma strict
    2.  
    3. // Change renderer's texture each changeInterval
    4. // seconds from the texture array defined in the inspector.
    5. var textures : Texture[];
    6. var changeInterval = 0.33;
    7.  
    8. function Update() {
    9.    
    10.     var proj : Projector = GetComponent (Projector);
    11.  
    12.    
    13.     if( textures.length == 0 ) // nothing if no textures
    14.         return;
    15.  
    16.     // we want this texture index now
    17.     var index : int = Time.time / changeInterval;
    18.     // take a modulo with size so that animation repeats
    19.     index = index % textures.length;
    20.     // assign it
    21.     proj.material.mainTexture = textures[index];
    22. }
     
  3. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    VIC20, thats SUPER Expensive, doing a GetComponent every frame when the reference to the projector never changes.

    Code (csharp):
    1. #pragma strict
    2.  
    3. // Change renderer's texture each changeInterval
    4. // seconds from the texture array defined in the inspector.
    5. var textures : Texture[];
    6. var changeInterval = 0.33;
    7. var proj : Projector;  // you can drag the projector onto this in the editor, then get rid of the Start() function if you want.
    8.  
    9. function Start() {
    10.      proj = GetComponent (Projector);
    11. }
    12.  
    13. function Update() {
    14.  
    15.     if( textures.length == 0 ) // nothing if no textures
    16.         return;
    17.  
    18.     // we want this texture index now
    19.     var index : int = Time.time / changeInterval;
    20.     // take a modulo with size so that animation repeats
    21.     index = index % textures.length;
    22.     // assign it
    23.     proj.material.mainTexture = textures[index];
    24. }
    Cheers :)
     
  4. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,682
    uups :oops: thank you!
     
  5. SHoe

    SHoe

    Joined:
    May 13, 2013
    Posts:
    14
    How can I make this work on the projector shader?
     
    joshua-lyness likes this.
  6. joshua-lyness

    joshua-lyness

    Joined:
    Jul 30, 2013
    Posts:
    8
    Urgh I really need this to work too. I'm using the light projector at the minutes but its too dark, I need it to be additive not blend. -_-