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

public class Sun : MonoBehaviour {

    public static Orbiter gettable = Orbiter.none;
    public enum Orbiter { none, sun, god };
    public Orbiter orbiter;
    public Collider collider;

    private void Start()
    {
        if (orbiter == Orbiter.sun)
            Game.stars.Add(gameObject);
        if (orbiter == Orbiter.god)
            Game.gods.Add(gameObject);
    }

	void Update () {
        if (gettable >= orbiter)
            collider.enabled = true;
	}


    private void OnMouseDrag()
    {
        var mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        var stellarPlane = new Plane(Vector3.up, -Mathf.Round(transform.position.y));
        float distance;
        stellarPlane.Raycast(mouseRay, out distance);
        var pos = mouseRay.GetPoint(distance);
        if (Vector3.Distance(Game.player.transform.position, transform.position) < 10f)
            transform.position = pos;
    }
    private void OnMouseUp()
    {
        if (Vector3.Distance(Game.player.transform.position, transform.position) > 10f)
            return;
        if (Game.player.suns.Contains(gameObject))
            return;
        Game.player.AttachSun(gameObject, orbiter);
    }
}
