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. Dismiss Notice

ScrollingScript

Discussion in 'Scripting' started by xelvod, Feb 12, 2015.

  1. xelvod

    xelvod

    Joined:
    May 15, 2012
    Posts:
    90
    I found ScrollingScript which i needed for lava texture, but it only scroll diffuse texture.
    It would be great if this little script could scroll normal map and illumin which i need for lava.
    Here is the code... can anyone help me with this?

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ScrollingScript : MonoBehaviour
    5. {
    6.     public float scrollSpeed = 0.9f;
    7.     public float scrollSpeed2 = 0.9f;
    8.  
    9.     void FixedUpdate ()
    10.     {
    11.         float offset = Time.time * scrollSpeed;
    12.         float offset2 = Time.time * scrollSpeed2;
    13.  
    14.         renderer.material.mainTextureOffset = new Vector2 (offset2, -offset);
    15.     }
    16. }
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
  3. xelvod

    xelvod

    Joined:
    May 15, 2012
    Posts:
    90
  4. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    You can just call it more than once from the same script, but yeah
    Code (CSharp):
    1. void Update() {
    2.         float offset1 = Time.time * scrollSpeed;
    3.         float offset2 = Time.time * scrollSpeed;
    4.         renderer.material.SetTextureOffset("_MainTex", new Vector2(offset, 0));
    5.         renderer.material.SetTextureOffset("_BumpMap", new Vector2(offset2, 0));
    6.     }