using UnityEngine;
using System.Collections;
using System;

public class ScrollingSprite : TravellingThing
{
    public float speed = 5;
    public bool isEvent = false;

    private float multiplier = 1;
    public Action action;

    void Update()
    {
        var position = transform.localPosition;
        position.x -= Time.deltaTime * speed * multiplier;
        transform.localPosition = position;

        var cam = Camera.main;
        float height = cam.orthographicSize;
        float width = height * cam.aspect;
        var me = GetComponent<SpriteRenderer>();

        if (isEvent && position.x < 0.1f)
        {
            isEvent = false;
            GetComponentInParent<TravelController>().Stop(0);
            if (action != null) action();
        }

        if (me.bounds.max.x < -width)
        {
            Destroy(gameObject);
        }

    }

    public override void SetMultiplier(float speed)
    {
        multiplier = speed;
    }
}
