- Home /
Question by
TrungDQ_Reedor · Aug 11, 2014 at 10:58 AM ·
materialoffsetscrollingquad
Problem with using offset for scrolling screen
I have been using this script for a scrolling screen for awhile. It used to work perfectly. But for the past 2 weeks, suddenly the offset failed to work properly. And I don't have any idea on how to fix it.
Please tell me what is wrong. Thank you all very much.
#pragma strict
var Speed : float = 0f;
private var scroll : boolean = true;
private var _mod : float = 0f;
private var _modStep : float = 0.005f;
private var _textureWidth : float;
function Start () {
_textureWidth = gameObject.transform.localScale.x;
}
function FixedUpdate () {
//Debug.Log(scroll);
if (scroll) {
renderer.material.mainTextureOffset = new Vector2((_mod * Speed)%1, 0f);
_mod = _mod + _modStep;
if (_mod > _textureWidth) _mod = 0;
}
}
The script is credited to Mike Geig. I only take it from his video.
And the problem is this: https://www.dropbox.com/s/yihh5mdb34opuzt/offsetproblem.jpg
offsetproblem.jpg
(118.4 kB)
Comment
"failed to work properly" doesn't tell us much. Is it not working at all, or is it doing something wrong. The two most likely are: 1) you are not setting the 'speed' variable in the Inspector, and 2) you do not have the 'wrap' mode for the texture set to 'repeat'. Also I'm not sure why he bothers with the mod stuff.
Your answer
![](https://koobas.hobune.stream/wayback/20220613160333im_/https://answers.unity.com/themes/thub/images/avi.jpg)