Search Unity

When lerping, can't change offset

Discussion in 'Scripting' started by _JoshC, Jul 19, 2019.

  1. _JoshC

    _JoshC

    Joined:
    Mar 8, 2015
    Posts:
    9
    Hi,

    Currently I'm making something which includes multiple materials. I wanted to make a scrolling effect so I changed the offset of the material Main Texture to make it happen. This works fine and well. But the moment it's lerping to another texture it stoppes moving. I used the debugger of Visual studio to check what happens and it seems like the Y-coordinate isn't affected while lerping.

    My scrolling background code:
    Code (CSharp):
    1.     private void ScrollBackground() {
    2.         Vector2 offset = _quadRenderer.material.mainTextureOffset;
    3.  
    4.         offset.y += Time.deltaTime * 0.02f;
    5.  
    6.         _quadRenderer.material.mainTextureOffset = offset;
    7.     }
    For lerping I used the code which can be found on the Unity Docs:
    Code (CSharp):
    1. float lerp = Mathf.PingPong(Time.time, duration) / duration;
    2. rend.material.Lerp(material1, material2, lerp);
    My guess is that because of lerping between two materials there is not really a main material present. So my question is: how can I move the material to create a scrolling effect while lerping at the same time?


    Thanks in advance!

    Kind regards,
    Josh
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,334
    This subforum is for issues with Unity's documentation. Please post in the Scripting subforum if you have problem with scripts.
     
  3. _JoshC

    _JoshC

    Joined:
    Mar 8, 2015
    Posts:
    9
    Oh snap, I thought I was in the scripting... I have too many tabs open. Thanks!