Exemplo n.º 1
0
        /// <summary>
        /// 与npc相遇时只调整方向,不调整位置
        /// </summary>
        /// <param name="battlePlayerCtr">Battle player ctr.</param>
        private IEnumerator AdjustTowards(BattlePlayerController battlePlayerCtr)
        {
            yield return(new WaitUntil(() => battlePlayerCtr.isIdle));

            float posOffsetX = battlePlayerCtr.transform.position.x - this.transform.position.x;
            float posOffsetY = battlePlayerCtr.transform.position.y - this.transform.position.y;

            if (posOffsetX > 0.1f)
            {
                battlePlayerCtr.TowardsLeft();
                baCtr.TowardsRight(false);
            }
            else if (posOffsetX < -0.1f)
            {
                battlePlayerCtr.TowardsRight();
                baCtr.TowardsLeft(false);
            }
            else if (posOffsetY > 0.1f)
            {
                battlePlayerCtr.TowardsDown();
                baCtr.TowardsUp(false);
            }
            else
            {
                battlePlayerCtr.TowardsUp();
                baCtr.TowardsDown(false);
            }

            switch (battlePlayerCtr.towards)
            {
            case MyTowards.Up:
                if (battlePlayerCtr.transform.position.x < transform.position.x)
                {
                    baCtr.TowardsLeft();
                    if (battlePlayerCtr.transform.position.x <= transform.position.x - 0.5f)
                    {
                        battlePlayerCtr.TowardsRight();
                    }
                    else if (battlePlayerCtr.transform.position.x >= transform.position.x + 0.5f)
                    {
                        battlePlayerCtr.TowardsLeft();
                    }
                }
                else
                {
                    baCtr.TowardsRight();
                    if (battlePlayerCtr.transform.position.x <= transform.position.x - 0.5f)
                    {
                        battlePlayerCtr.TowardsRight();
                    }
                    else if (battlePlayerCtr.transform.position.x >= transform.position.x + 0.5f)
                    {
                        battlePlayerCtr.TowardsLeft();
                    }
                }
                break;

            case MyTowards.Down:
                if (battlePlayerCtr.transform.position.x < transform.position.x)
                {
                    baCtr.TowardsLeft();
                    if (battlePlayerCtr.transform.position.x <= transform.position.x - 0.5f)
                    {
                        battlePlayerCtr.TowardsRight();
                    }
                    else if (battlePlayerCtr.transform.position.x >= transform.position.x + 0.5f)
                    {
                        battlePlayerCtr.TowardsLeft();
                    }
                }
                else
                {
                    baCtr.TowardsRight();
                    if (battlePlayerCtr.transform.position.x <= transform.position.x - 0.5f)
                    {
                        battlePlayerCtr.TowardsRight();
                    }
                    else if (battlePlayerCtr.transform.position.x >= transform.position.x + 0.5f)
                    {
                        battlePlayerCtr.TowardsLeft();
                    }
                }
                break;

            case MyTowards.Left:
                baCtr.TowardsRight();
                break;

            case MyTowards.Right:
                baCtr.TowardsLeft();
                break;
            }

            ExploreManager.Instance.ShowNPCPlane(this);
        }