- Home /
How do I do 2d parallax
Been trying to do 2d parallax but I can’t find A way to do it with out using another camera or using the z position of sprites.
Answer by duke2go · Nov 21, 2018 at 07:56 AM
I learned a lot about parallax scrolling by watching YouTube tutorials believe it or not. I've got a cloud scrolling script that might help you.
public class Clouds : MonoBehaviour {
public float speed;
private float xDir;
// Use this for initialization
void Start () {
xDir = transform.position.x;
}
// Update is called once per frame
void Update () {
xDir -= Time.deltaTime * speed;
transform.position = new Vector3(xDir, transform.position.y, transform.position.z);
if (transform.position.x == 10) {
transform.position = new Vector3 (100, transform.position.y, transform.position.x);
}
}
}
I know the code worked to make the clouds scroll to the left and wrap back around to the right once the sprite had reached a certain horizontal position. I'd also recommend watching some of the same YouTube tutorials I did to learn more. These are 2 good series that might help answer some of your questions.
https://ru-clip.net/video/QkisHNmcK7Y/scrolling-parallax-unity-2d-game-mechanics-unity-3d.html
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
parallax on x, But how on the y as well? [Solved] 1 Answer