- Home /
Question by
John Sartain · Mar 16, 2014 at 02:04 AM ·
scroll view
How to change diection to up of a scrolling background
I have a scrolling background how do I make it change directions. Im using: var ScrollSpeed : float = 0.5;
function Update () {
var offset : float = Time.time * ScrollSpeed;
renderer.material.SetTextureOffset ("_MainTex", Vector2(offset,0));
}
Comment
Answer by robertbu · Mar 16, 2014 at 02:08 AM
The direction and speed of scrolling this fragment:
Vector2(offset, 0)
Currently is it scrolling on the 'x' axis. To scroll on the 'y' axis, change to:
Vector2(0, offset);
As for direction you can handle it here, but it would be easier and a bit more flexible to just use the sign of the 'ScrollSpeed' for direction. So if it is scrolling the wrong way ScrollSpeed to -0.5. Note you must change public variables in the Inspector. Changing them in code does nothing to an already attached script.