- Home /
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 :
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);
}
}
Answer by flamy · Mar 14, 2013 at 12:12 PM
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.
Answer by Poelie · Mar 14, 2013 at 12:35 PM
this is the script for resetting the game.
HUDScript
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?
Your answer

Follow this Question
Related Questions
Title screen is off to the side in build 2 Answers
Why is my texture offset accelerating? 0 Answers
2D Background Generator 1 Answer
GUI background changed, don't know how to reset it. 2 Answers
How will i goes fresh level? 0 Answers