- Home /
Question by
Maximus2019 · Sep 28, 2015 at 07:55 PM ·
background
Horizontal Scrolling Background
using UnityEngine;
//This script controls the scrolling of the background
public class Background : MonoBehaviour
{
public float speed = 0.1f; //Speed of the scrolling
void Update ()
{
//Keep looping between 0 and 1
float x = Mathf.Repeat (Time.time * speed, 1);
//Create the offset
Vector2 offset = new Vector3 (0, x);
//Apply the offset to the material
GetComponent<Renderer>().sharedMaterial.SetTextureOffset ("_MainTex", offset);
}
}
This allows my background to scroll vertically, but I'm trying to make it scroll horizontal. I tried changing the vectors, but it didn't do anything. Any help?
Comment
Best Answer
Answer by Kornikolia · Sep 28, 2015 at 09:04 PM
When I have changed this:
Vector2 offset = new Vector3 (0, x);
To this:
Vector2 offset = new Vector3 (x, 0);
It started scroll from vertical to horizontal....
Thank you! I had thought that I needed to changed the Vectors around, but nope. :P
Thanks again!
Answer by TheEpicBirb · Nov 25, 2021 at 09:34 PM
Ayooo this helped me a lot for a 2d flight sim im making thx!
Your answer

Follow this Question
Related Questions
Large background image, should I cut it? 1 Answer
background GUI texture 2 Answers
Changing camera background color in runtime 3 Answers
Trying to change button background using materials 1 Answer
PNG got green background when imported? 0 Answers