Question by
MrSerebral · Feb 13, 2017 at 03:39 PM ·
animationtexturematerialoffset
I'm trying to get a material on a gameobject to offset slightly over time and can't figure it out.
I just started messing with Unity recently and am just toying with the mechanics of the engine just to get an idea of how things work. Anyway what i'm going for is to have the material texture to offset slightly on a x/y axis to give the gameobject a "animated" texture. I've attached my code. Any help is much appreciated!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LavaOffsetMovement : MonoBehaviour {
public float OffsetSpeed = 5.0f;
public GameObject LavaFloor;
public Renderer rend;
void Start () {
rend = LavaFloor.GetComponent<Renderer>();
}
void Update () {
float offset = Time.deltaTime * OffsetSpeed;
rend.material.SetTextureOffset("Lava", new Vector2(offset, offset));
}
}
Comment