Can anyone explain what an offset is?
Hi. I am new with Unity and I am watching a tutorial, but I don't understand what the offset is. Can anyone please explain to me every step from this code?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class AnimatedTexture : MonoBehaviour {
public Vector2 speed = Vector2.zero;
private Vector2 offset = Vector2.zero;
private Material material;
// Use this for initialization
void Start () {
material = GetComponent<Renderer> ().material;
offset = material.GetTextureOffset ("_MainTex");
}
// Update is called once per frame
void Update () {
offset += speed * Time.deltaTime;
material.SetTextureOffset ("_MainTex", offset);
}
}
Also I want to know what Set/GetTextureOffset(...) does. Thank you.
$$anonymous$$ust be offset for the tiled texture on a material. Imagine a quad with a texture on it, offset 0.5 means texture will start drawing at the center of the quad, middle will be at the end and at the start of left side, and the end of the texture will be also at the center (we are talking about only x axis). I suppose in your case it is used to simulate scrolling nackground or something else moving...
Your answer
Follow this Question
Related Questions
Access Top and Right Variables from RectTransform 0 Answers
How to destroy only a clone in Unity 3d? 0 Answers
Dreamlo Leaderbord issue 0 Answers
Roll a Ball tutorial: Ball doesn't move 0 Answers