- Home /
Question related to optimization in unity3d
Hi
I am new to unity, I am working on a 2d game. I have created a background that scrolls infinitely over time. For that I have created a plane as a game object and assign it a material and to that material I have assigned a texture. now I change offset of the texture every frame through a script. It looks fine when the game starts but if I let game running for about 30 mins or so it starts showing waves in the background here is my code
public class BackgroundManager : MonoBehaviour {
public int materialIndex = 0;
public Vector2 uvAnimationRate = new Vector2( 0.0f, 1.0f );
public string textureName = "_MainTex";
public float speed = 0.5f;
Vector2 uvOffset = Vector2.zero;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
uvOffset -= ( uvAnimationRate * Time.deltaTime * speed) ;
if( renderer.enabled )
{
renderer.materials[ materialIndex ].SetTextureOffset( textureName, uvOffset );
}
}
}
An Edit: I will be deploying this code to android/ios devices. please help
If you know specific number for one background loop, you can $$anonymous$$us that amount each loop. Similar like circle angle 361 is the same as 1 degree. Zeroing the number wouldn't be the best option because it will result in slight "laag", because the actual number will be higher than that zero border.
if(currentPosition > amountForOneLoop) currentPosition -= amountForOneLoop;
Answer by pointcache · Oct 28, 2013 at 08:36 AM
is it possible to use 2 planes and swap them with zeroing positions each loop?
@pointcache : I can use that approach as well but as for as I know this is better approach, also just an edit that I am deploying to android/ios
Your answer
![](https://koobas.hobune.stream/wayback/20220613120758im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Optimal # of Faces for many mesh scene for mobile 1 Answer
Changing the splash screen background color 3 Answers
GUI system for android? 1 Answer
What is static batching and dynamic batching? 0 Answers
Joystick trouble... 0 Answers