- Home /
Texture / Material offset doesn't work
Hey,
I want to make a 2D Sprite animation, buy changing the offset of the material depending on the rotation. So I made a material with the shader transparent/cutout/diffuse and the texture is a png image which has every step inside to "roll" with offset
There is an empty gameobject without a renderer. In this empty game object is a 3D text with Mesh renderer and the font material. in the empty game object there is also a plane with a mesh renderer, which has the material I want to "scroll" with offset.
Here is the script on the empty gameobject (reduced to the problem):
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
public Renderer mat1;
public float i;
// Use this for initialization
void Start ()
{
mat1 = transform.FindChild ("playerPlane").renderer;
}
// Update is called once per frame
void Update ()
{
i++;
if(Input.GetKey (KeyCode.W))
{
mat1.material.mainTextureOffset = new Vector2(i,20f);
Debug.Log(mat1.material.GetTextureOffset("_MainTex") + " - " + i);
}
}
}
the print function works correctly, but the image doesnt change, I see something on the edges like black pixels that appear and dissappear, maybe something is moving, but not the image itself.
Anyone an idea?
Answer by ScroodgeM · Jul 25, 2012 at 10:53 AM
texture offset is scaled 1:1 to texture's size. so if you want to shift half texture you should offset it by 0.5
you can very many times shift it by natural numbers (1,2,3...) and you will not see any effect.
lol ye I just got it by myself right before you answered, but thx for the answer!
I couldn't believe I didn't find such a simple information by myself when I searched on google and the manuals. Just checked the manual again, nothing about 0-1 there...
thx!
Your answer
Follow this Question
Related Questions
Changing button texture by setting a texture offset of a sprite sheet?(SOLVED) 1 Answer
Offset detail texture in c# 1 Answer
Overlay texture on sprite 0 Answers
Shader Edit Help: 2D Outline Coloring 2 Answers
Why can't I animate texture offset? 1 Answer