﻿using UnityEngine;
using System.Collections;

namespace AC.CombatExample
{

	public class Shotgun : Weapon
	{

		#region Variables

		[SerializeField] private Renderer muzzleFlash = null;

		#endregion


		#region UnityStandards

		private void Awake ()
		{
			muzzleFlash.enabled = false;
		}

		#endregion


		#region PublicFunctions

		public override void OnAttack (Char character)
		{
			if (attackSound)
			{
				AudioSource.PlayClipAtPoint (attackSound, transform.position);
			}
			StartCoroutine (ShowMuzzleFlash ());

			RaycastHit raycastHit;
			if (Physics.SphereCast (character.transform.position + Vector3.up, 0.35f, character.transform.forward, out raycastHit, range))
			{
				ProcessHit (raycastHit);
			}
		}

		#endregion


		#region PrivateFunctions

		private IEnumerator ShowMuzzleFlash ()
		{
			muzzleFlash.enabled = true;
			yield return new WaitForSeconds (0.1f);
			muzzleFlash.enabled = false;
		}

		#endregion

	}

}