Hey guys i am trying to make a background in a 2D game which slowly scrolls but i am making a transition to enter a new world but it seems like unity just ignores my bool in the if statement?? anyone know how come?
the script is attached to two different pictures which then scrolls
float moveSpeed = -0.02f;
float World2 = 20f;
float maxHeight = 0f;
bool transition = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.Translate (0, moveSpeed, 0);
maxHeight = renderer.bounds.size.y;
Vector3 pos = transform.position;
if (-maxHeight >= pos.y) {
pos.y = +maxHeight + moveSpeed;
transform.position = pos;
}
if (Score.score >= World2) {
if (pos.y >= 11.42f && transition == false){
Debug.Log ("HALLLO!!!!!");
gameObject.GetComponent<SpriteRenderer> ().sprite = Resources.Load("World2Trans", typeof(Sprite)) as Sprite;
Vector3 scale = transform.localScale;
scale.y = 1.01f;
transform.localScale = scale;
transition = true;
}
if (pos.y >= 11.42f && transition == true){
gameObject.GetComponent<SpriteRenderer> ().sprite = Resources.Load("World2", typeof (Sprite)) as Sprite;
}
}
}
}