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

uv animation scripts?

Discussion in 'Scripting' started by sgtkoolaid, Oct 14, 2015.

  1. sgtkoolaid

    sgtkoolaid

    Joined:
    May 11, 2010
    Posts:
    897
    is there any uv animation scripts I can buy or download that allows me to scroll a texture across a plane or mesh face? thanks for the assistance.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,797
    You might wanna check around the asset store forum area for that sort of thing.

    If you wanna take a crack at writing it yourself, it's pretty easy. You need to get a reference to the Material involved, and then move the texture offsets if you just want gross scrolling to happen. The field shortcut in your material object is .mainTextureOffset and it is a Vector2.

    If you want weirder per-UV stuff, then you will need to read the mesh info out of the MeshFilter, figure out what verts you want, and update their individual UV coords, which is a bit more involved.
     
  3. sgtkoolaid

    sgtkoolaid

    Joined:
    May 11, 2010
    Posts:
    897
    I am not a scripter kurt lol. so yeah but I also searched on the asset store and nothing popped out as somethgin that could help me with that very thing. or maybe my search words were less than specific, anyone know what popular apps that can do that?
     
  4. vintar

    vintar

    Joined:
    Sep 18, 2014
    Posts:
    90
    Code (csharp):
    1. using UnityEngine;
    2.  
    3. public class MoveUVS : MonoBehaviour
    4. {
    5.   float _updateDelay = 0.05f;
    6.   float _nextUpdateTime;
    7.   public Renderer Rend;
    8.   Vector2 _offset = new Vector2(0, 1);
    9.   Vector2 _uvOffset = Vector2.zero;
    10.   public bool _isWater;
    11.   bool _set;
    12.  
    13.   void Update()
    14.   {
    15.     if (_isWater)
    16.     {
    17.       _uvOffset += _offset * Time.deltaTime;
    18.       Rend.material.SetTextureOffset("_MainTex", _uvOffset);
    19.     }
    20.     else
    21.     {
    22.       if (Time.time > _nextUpdateTime)
    23.       {
    24.         _nextUpdateTime = Time.time + _updateDelay;
    25.         _set = !_set;
    26.         if (_set)
    27.         {
    28.           _uvOffset += _offset * Time.deltaTime;
    29.           Rend.material.SetTextureOffset("_MainTex", _uvOffset);
    30.         }
    31.         else
    32.         {
    33.           _uvOffset -= _offset * Time.deltaTime;
    34.           Rend.material.SetTextureOffset("_MainTex", _uvOffset);
    35.         }
    36.       }
    37.     }
    38.   }
    39. }
    I made a mincrafty type game and used this code to make it look like running water if _isWater is true or shimmer like a fire. Add this script to your object and drag the renderer into the slot in inspector.
     
  5. sgtkoolaid

    sgtkoolaid

    Joined:
    May 11, 2010
    Posts:
    897
    thanx vintar i will give that a whirl, I will report back to you.
     
  6. sgtkoolaid

    sgtkoolaid

    Joined:
    May 11, 2010
    Posts:
    897
    got it to apply tot he object, but nothing happens after I apply the renderer.