using UnityEngine;
using System.Collections;

public class LasorAlt1Controller : MonoBehaviour, IInteractable, IResetable
{
	private Vector3 shotAngle;
	private float shotDistance;
	[SerializeField]
	private GameObject beam;
	[SerializeField]
	private float distanceScaleMultiplier = 0.4f;
	[SerializeField]
	private float distanceScaleTweak = 0.01f;
	[SerializeField]
	private Transform emmisionPoint;
	private bool shooting = true;
	[SerializeField]
	private ParticleSystem particles;
	[SerializeField]
	private float spinRate = 1f;
	
	void Update()
	{
		shotAngle = transform.TransformDirection(Vector2.up);
		RaycastHit2D cast = Physics2D.Raycast(emmisionPoint.position, shotAngle);
		shotDistance = cast.distance;
		Vector3 newScale = new Vector3(0.05f, (cast.distance*distanceScaleMultiplier) - distanceScaleTweak, 1f);
		beam.transform.localScale = newScale;
		if(cast && cast.collider.CompareTag("Player"))
		{
			cast.collider.gameObject.GetComponent<DeathSpawnController>().KillPlayer();
		}
	}
	
	public void Interact()
	{
		if(GetComponent<Animator>().speed == 0f)
		{
			GetComponent<Animator>().speed = 1f;
		}
		else if(GetComponent<Animator>().speed == 1f)
		{
			GetComponent<Animator>().speed = 0f;
		}
	}
	
	public void Reset()
	{
		GetComponent<Animator>().speed = 0f;
	}
}