How do i reset the backgrounds offset

I am trying to make an game where the background moves, with objects on it.
but when i die, and i restart the game the background doesn’t reset.

i want to reset the offset of my script.

this is my script :


using UnityEngine;
using System.Collections;

public class BackgroundScrollScript : MonoBehaviour {

public float scrollSpeed;

private Material OffsetStart;

// Update is called once per frame
void Update () {
	 float offset = Time.time * scrollSpeed;
    renderer.material.SetTextureOffset("_MainTex", new Vector2(0, offset));
	//Checks if background should reset.
	if(GameObject.Find("Achtergrond").GetComponent().resetBackground == true){
		renderer.material.SetTextureOffset("_MainTex", new Vector2(0, + offset));
		GameObject.Find("Achtergrond").GetComponent().resetBackground = false;

void SetTexture () {
	transform.renderer.material.mainTextureOffset = new Vector2(0.0f, 0.0f);	


If you are using Application.LoadLevel to restart, this problem wont be there, the offset will be set automatically.

I guess u are manually setting the player back at certain position and strt the game again. In that case when the player dies set this variable to true.

GameObject.Find(“Achtergrond”).GetComponent().resetBackground= true;

or simply set the offset to some value when the player respawns.

this is the script for resetting the game.


if (GUI.Button (new Rect(Screen.width/2, Screen.height/2 - 150, 200, 100), “Restart”)){
Application.LoadLevel (“Bumper” );
resetBackground = true;
showScore = false;

i am using Application.LoadLevel, and it still gives the same problem.

How do i set the offset value?