- Home /
Question by
namarts · Aug 13, 2017 at 06:03 PM ·
lagbackgroundscrollingjerky
scrooling background
hi, I made a script to kinda scroll my background,i made two backgrounds and replacing them when they get out of camera but it is causing jerks and fps drops, i just want someone to check whats wrong with the script and is there any better way of scrolling background without any lags, by the way I am working on an android game.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class bgscroll : MonoBehaviour {
public Vector2 velocity = new Vector2(0, -2);
private float spriteWidth;
private Transform cameraTransform;
public Rigidbody2D rb;
void Start() {
cameraTransform = Camera.main.transform;
SpriteRenderer sr = gameObject.GetComponent<SpriteRenderer>() as SpriteRenderer;
spriteWidth = sr.sprite.bounds.size.y;
rb.velocity = velocity;
}
void Update() {
if( ( transform.position.y + spriteWidth ) < cameraTransform.position.y ) {
Vector3 newPos = transform.position;
newPos.y += 2.0f * spriteWidth;
transform.position = newPos;
}
}
}
please give me the best way to scroll background for android!!!!!!!!!!!
Comment
Your answer
Follow this Question
Related Questions
Perspective scrolling background 1 Answer
Parallax scrolling background performance problem 4 Answers
2D Parallax Background 4 Answers
Moving Background with translated images 1 Answer
Making a point and click background. 0 Answers