using UnityEngine;
using System.Collections;
using Framework.Entities;
using Framework.ActorComponents;
using Framework.Extensions;

public class MissileBehaviour : CoreBehaviour
{
    public float force = 1f;
    public Vector3 targetPosition;
    private Rigidbody rigidbody;

    protected override void InnerAwake()
    {
        this.rigidbody = GetComponent<Rigidbody>();
        
    }

    protected override void InnerStart()
    {
        this.rigidbody.AddForce((this.targetPosition - this.transform.position).normalized * this.force, ForceMode.Impulse);
    }

    protected override void InnerUpdate()
    {
        this.transform.Rotate(new Vector3(5f, 5f, 5f));
    }

    void OnCollisionEnter(Collision collision)
    {
        collision.collider.gameObject.Interact(new Health.HurtAction(50));
        Instantiate(Resources.Load("DestroyField"), this.transform.position + (Vector3.up * 0.5f), new Quaternion());
        Destroy(this.gameObject);
    }
}
