so I've created a 2D sidescroller game, the technique I used is to keep the player on the same place, and move the obstacles towards him. I also offset the ground and backdrop constantly to create the illusion of player moving.

The ground texture is on a quad, and the texture wrap mode is set to repeat. In the editor everything is running fine as I wanted, however when I build it (WebGL), in the browser the ground doesn't seem as if it is set to Repeat but rather Clamp. Here's how it looks:

enter image description here

You can see from the left part of the image the ground doesn't repeat, the strange thing is that, after the game runs for a few more seconds it fixes, and then in a few seconds becomes like that again.

heres the code attached to the ground to keep it offsetting constantly:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Offset : MonoBehaviour {

public float scrollSpeed;
public Material mat;

private float offset;

// Use this for initialization
void Start () {
    mat = GetComponent<Renderer>().material;

// Update is called once per frame
void Update () {
    offset = Mathf.Repeat(Time.time * scrollSpeed, 1);
    mat.mainTextureOffset = new Vector2(offset, mat.mainTextureOffset.y);

What may I be doing wrong, and how can I fix it?

Thanks in advance!

  • \$\begingroup\$ based on my experience it's more convenient to use normal movement with spawning obstacles in front of character, so you don't need to sync other in-game objects with your ground texture offset \$\endgroup\$ – Yevhen Jan 14 '17 at 19:16
  • \$\begingroup\$ Would that be less performance heavy? \$\endgroup\$ – Vadim Tatarnikov Jan 15 '17 at 7:49
  • \$\begingroup\$ why you use Time.time ? Time.deltaTime is alot better ( for me ) \$\endgroup\$ – user6668201 Jan 15 '17 at 13:33
  • 1
    \$\begingroup\$ Time.time only increases (which causes an increase in offset), where Time.deltaTime varies depending on the time in between frames \$\endgroup\$ – Vadim Tatarnikov Jan 15 '17 at 13:35
  • \$\begingroup\$ @VadimTatarnikov The performance different is slim. You should worry about performance only if you notice something wrong with it. At the end of the day, if it runs 0.0001 seconds faster, is it really worth it? \$\endgroup\$ – TomTsagk Jul 23 '18 at 11:51

for texture scrolling you should use "Repeat" in import settings instead of "clamp"

  • 1
    \$\begingroup\$ I have done that \$\endgroup\$ – Vadim Tatarnikov Jan 15 '17 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.