﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AsteroidClicker : MonoBehaviour
{
    //mask the things we want to go Kaboom
    public LayerMask mask;
    public int power = 1;

    //Click on some asteroids!
    void Update()
    {
        //If left click
        if (Input.GetMouseButtonDown(0))
        {
            //create a Ray from the cursor using the Main Camera
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            //create a temporary holder for the Raycast results
            RaycastHit hit = new RaycastHit();

            //Raycast along a ray, put the results in hit variable
            //Cast out to 1000 units, only cast against things in the LayerMask, ignore triggers
            if (Physics.Raycast(ray, out hit, 1000, mask, QueryTriggerInteraction.Ignore))
            {
                //Try to get a reference to the Asteroid component
                Asteroid roid = hit.collider.GetComponent<Asteroid>();

                //Did the thing we clicked on have an Asteroid component?
                if(roid != null)
                {
                    //Hit it!
                    roid.Damage(power, hit.normal);
                }
            }
        }


    }
}
