Skip to content

Commit

Permalink
speeded up background animation
Browse files Browse the repository at this point in the history
  • Loading branch information
francescaguzzi committed Dec 27, 2023
1 parent 9d67f9c commit 5b43c39
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions Assets/Scripts/ParallaxScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,22 @@ public class ParallaxScript : MonoBehaviour
// script that slowly moves the background to create a parallax effect
// right - left movement

private float speed = 0.5f;
private float speed = 1f;
private Vector3 startPosition;
private int direction = 1;

void Start()
{
void Start() {
startPosition = transform.position;
}
void Update() {

// Update is called once per frame
void Update()
{
// max x position is 5, min x position is -5
transform.position += Vector3.right * direction * speed * Time.deltaTime;

if (transform.position.x >= 4.9f)
{
direction = -1; // Inverti la direzione quando raggiungi il limite destro
}
if (transform.position.x >= 4.9f)
direction = -1;
else if (transform.position.x <= -4.9f)
{
direction = 1; // Inverti la direzione quando raggiungi il limite sinistro
}
direction = 1;

}
}

0 comments on commit 5b43c39

Please sign in to comment.