using UnityEngine;
using System.Collections;

public class IdleSprites : MonoBehaviour {

    public Sprite Frame1;
    public Sprite Frame2;
    public float SwitchesPerSecond = 2.5f;

    private SpriteRenderer rend;
    private float offset; 

    void Start()
    {
        rend = GetComponent<SpriteRenderer>();
        offset = Random.Range(0, 0.99f); // prevents anims from globally syncing on Time clock
    }

    void Update()
    {
        int now = Mathf.RoundToInt((Time.time+offset) * SwitchesPerSecond);
        if ((now % 2) == 0)
            rend.sprite = Frame1;
        else
            rend.sprite = Frame2;
    }
}
