using UnityEngine;
using System.Collections;

public class MainBodyStateOneD : FiniteState
{
    Transform sphere;
    Transform halo;
    MainBody self;
    public override void Init()
    {
        self = subject as MainBody;
        sphere = self.sphere;
        sphere.GetComponent<MeshRenderer>().enabled = false;
        sphere.gameObject.SetActive(false);
        self.parti.Play();
        halo = self.halo;
        halo.gameObject.SetActive(true);
        sphere.GetComponent<SphereCollider>().radius = 0.3f;
    }
    public override void Update()
    {
        if (sphere.transform.position.x != 0)
            sphere.transform.localPosition = Vector3.MoveTowards(sphere.transform.localPosition, Vector3.zero, 10 * Time.deltaTime);
        if (Input.GetMouseButtonDown(0))
        {
            //sphere vanish
            if (!sphere.gameObject.activeSelf)
            {
                sphere.gameObject.SetActive(true);
                halo.GetComponent<SpriteRenderer>().sprite = self.click;
                //self.parti.Stop();
                self.StartCoroutine(LetSphereEmerge(self.vanishDuration));
            }
        }
        self.MoveSelf(self.speed_1);
        halo.transform.position = sphere.transform.position;
    }
    IEnumerator LetSphereEmerge(float duration)
    {
        yield return new WaitForSeconds(duration);
        halo.GetComponent<SpriteRenderer>().sprite = self.normal;
        sphere.gameObject.SetActive(false);
        //self.parti.Play();
    }
}
