Created
November 21, 2014 17:35
-
-
Save DarkDesire/730d01e6d2ae98e9e2d5 to your computer and use it in GitHub Desktop.
Scroll 2d Background
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class Done_BGScroller : MonoBehaviour | |
{ | |
public float scrollSpeed; | |
public float tileSizeZ; | |
private Vector3 startPosition; | |
void Start () | |
{ | |
startPosition = transform.position; | |
} | |
void Update () | |
{ | |
float newPosition = Mathf.Repeat(Time.time * scrollSpeed, tileSizeZ); | |
transform.position = startPosition + Vector3.forward * newPosition; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class OffsetScroller : MonoBehaviour { | |
public float scrollSpeed; | |
private Vector2 savedOffset; | |
void Start () { | |
savedOffset = renderer.sharedMaterial.GetTextureOffset ("_MainTex"); | |
} | |
void Update () { | |
float y = Mathf.Repeat (Time.time * scrollSpeed, 1); | |
Vector2 offset = new Vector2 (savedOffset.x, y); | |
renderer.sharedMaterial.SetTextureOffset ("_MainTex", offset); | |
} | |
void OnDisable () { | |
renderer.sharedMaterial.SetTextureOffset ("_MainTex", savedOffset); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class StripScroller : MonoBehaviour { | |
public float scrollSpeed; | |
public float tileSizeZ; | |
private Vector2 savedOffset; | |
private Vector3 startPosition; | |
void Start () | |
{ | |
startPosition = transform.position; | |
savedOffset = renderer.sharedMaterial.GetTextureOffset ("_MainTex"); | |
} | |
void Update () | |
{ | |
float x = Mathf.Repeat (Time.time * scrollSpeed, tileSizeZ * 4); | |
x = x / tileSizeZ; | |
x = Mathf.Floor (x); | |
x = x / 4; | |
Vector2 offset = new Vector2 (x, savedOffset.y); | |
renderer.sharedMaterial.SetTextureOffset ("_MainTex", offset); | |
float newPosition = Mathf.Repeat(Time.time * scrollSpeed, tileSizeZ); | |
transform.position = startPosition + Vector3.back * newPosition; | |
} | |
void OnDisable () { | |
renderer.sharedMaterial.SetTextureOffset ("_MainTex", savedOffset); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment