You are on page 1of 2

Space Trooper 1 (Part 1) – Background Scrolling

1. Set the screen resolution from the Game Window.


2. Create several folders for the project; that is Scenes, Audio, Textures,
Animations, Scripts and Prefabs.
3. Set the camera projection from Perspective to Orthographic.
4. Set the desire camera size:
1
Ideal size = × height of the screen resolution.
2
5. Import all the sprites needed. Make sure they are changed to 2D sprites from
the Inspector panel. Select the suitable Max Size and Format accordingly.
6. Add an empty game object named “Background” in the hierarchy. Add the
background image to this Background game object.
7. Add the identical background image to this Background game object again
but with the position next to the 1st image and is rotated 180 ° along the y-
axis.
8. Add a new script named BackgroundController.cs as below:
public class BackgroundController : MonoBehaviour {
private float width;
private SpriteRenderer spriteRenderer;
public float movingRate = 100f;

protected void Start () {


spriteRenderer = GetComponent<SpriteRenderer> ();
width = spriteRenderer.sprite.texture.width *
transform.parent.localScale.x;
}

protected void Update () {


Vector3 pos = transform.position;
if (pos.x + width/2 < -Camera.main.pixelWidth / 2) {
pos.x += width * 2;
}
pos.x -= movingRate * Time.deltaTime;
transform.position = pos;
}
}
9. Add the BackgroundController.cs to both the background images.
10. Play the project and the background should scroll repeatedly.

You might also like