Exemplo n.º 1
0
    public virtual IEnumerator LerpToTile(TileProxy tile, float time, bool firstTile = false)
    {
        Vector3 start = transform.position;
        Vector3 end   = BoardProxy.GetWorldPosition(tile.GetPosition());

        /*
         * Right here is where the animation needs to be set
         */
        Animator anim = transform.GetChild(0).GetComponent <Animator>();

        if (anim != null)
        {
            Vector3    theScale  = transform.localScale;
            Vector3Int animStart = GetPosition();
            Vector3Int animEnd   = tile.GetPosition();
            Vector3    diff      = animEnd - animStart;

            if (diff.x > 0)
            {
                Debug.Log("right");
                theScale.x = -1;
                anim.SetBool("IDLE_FRONT_LEFT", false);
                while (anim.GetBool("IDLE_FRONT_LEFT"))
                {
                }
                anim.SetBool("MV_BACK_LEFT", true);
                anim.SetBool("MV_FRONT_LEFT", false);
            }
            else if (diff.x < 0)
            {
                Debug.Log("left");
                theScale.x = 1;
                anim.SetBool("IDLE_FRONT_LEFT", true);
                while (!anim.GetBool("IDLE_FRONT_LEFT"))
                {
                }
                anim.SetBool("MV_BACK_LEFT", false);
                anim.SetBool("MV_FRONT_LEFT", true);
            }
            else
            {
                //Defender is right below or above attacker
                if (diff.y > 0)
                {
                    Debug.Log("up");
                    theScale.x = 1;
                    anim.SetBool("IDLE_FRONT_LEFT", false);
                    while (anim.GetBool("IDLE_FRONT_LEFT"))
                    {
                    }
                    anim.SetBool("MV_BACK_LEFT", true);
                    anim.SetBool("MV_FRONT_LEFT", false);
                }
                else if (diff.y < 0)
                {
                    Debug.Log("down");
                    theScale.x = -1;
                    anim.SetBool("IDLE_FRONT_LEFT", true);
                    while (!anim.GetBool("IDLE_FRONT_LEFT"))
                    {
                    }
                    anim.SetBool("MV_BACK_LEFT", false);
                    anim.SetBool("MV_FRONT_LEFT", true);
                }
            }
            transform.localScale = theScale;
        }
        float timer = 0f;

        while (timer < time)
        {
            //            Debug.Log(transform.position);
            transform.position = Vector3.Lerp(start, end, timer / time);
            timer += Time.deltaTime;
            yield return(0f);
        }

        data.SetPosition(tile.GetPosition());
        if (!GetData().IsDead())
        {
            tile.CreateAnimation(Glossary.fx.smoke1);
        }
        if (tile.OnFire() && !firstTile)
        {
            if (IsAttackedEnvironment(1))
            {
                transform.GetChild(0).GetComponent <SpriteRenderer>().enabled = false;
                transform.GetChild(0).GetComponent <Animator>().enabled       = false;

                //ConditionTracker.instance.EvalDeath(this);
            }
        }
        //AnimationInteractionController.InteractionAnimationGameobject(
        //BoardProxy.instance.glossary.GetComponent<Glossary>().skull, BoardProxy.instance.GetTileAtPosition(GetPosition()).gameObject, AnimationInteractionController.NO_WAIT, true);
    }