﻿using UnityEngine;
using System.Collections;

namespace Nostalgia.Example
{
	[AddComponentMenu("Nostalgia/Example/MoveFloor")]
	public sealed class MoveFloor : MonoBehaviour
	{
		public Vector2 speed = new Vector2(0.0f, -5.0f);
		public Bounds bounds = new Bounds(Vector3.zero, new Vector3(50.0f, 50.0f));

		Bounds _CheckArea;

		Rigidbody2D _Rigidbody;

		void Awake()
		{
			_Rigidbody = GetComponent<Rigidbody2D>();

			_CheckArea = new Bounds(bounds.center + transform.position, bounds.size);
		}

		void FixedUpdate()
		{
			Vector2 pos = _Rigidbody.position;
			pos += speed * Time.fixedDeltaTime;
			_Rigidbody.MovePosition(pos);

			if (!_CheckArea.Contains(pos))
			{
				Destroy(gameObject);
			}
		}
	}
}
