Exemplo n.º 1
0
        /// <summary>
        /// change the position in the current scene
        /// </summary>
        /// <param name="_idxPos"> my new position </param>
        /// <param name="_length"> number of LL </param>
        /// <param name="_duration"> duration of action </param>
        public void ChangePos(int _idxPos, int _length, float _duration)
        {
            mCollider.enabled = false;
            Vector3 newPos = CalculatePos(_idxPos, _length);

            Vector3 dist = (gameObject.transform.position - newPos) / 2;

            Vector3 pivot = gameObject.transform.position - dist;

            //dist is only on x
            float radius = dist.x + 0.1f;

            float accuracy = 4f;

            for (int i = 1; i <= accuracy; ++i)
            {
                Vector3 p = Vector3.zero;
                p   += pivot;
                p.x += Mathf.Cos(3.14f * (i / accuracy)) * radius;
                p.z += Mathf.Sin(3.14f * (i / accuracy)) * radius;

                positions.Add(p);
            }


            PlayAnimation(LLAnimationStates.LL_walking);
            mLetter.SetWalkingSpeed(1);
            mLetter.HasFear = true;

            transform.DOLookAt(positions[0], 1f);

            TweenerCore <Vector3, Path, PathOptions> value = transform.DOPath(positions.ToArray(), _duration, PathType.CatmullRom);

            value.OnWaypointChange(delegate(int wayPoint) {
                if (wayPoint < positions.Count)
                {
                    transform.DOLookAt(positions[wayPoint], 1f);
                }
            });
            value.OnComplete(delegate {
                transform.DOLookAt(transform.position + Vector3.back, 1f);
                positions.Clear();
                PlayAnimation(m_oDefaultIdleAnimation);
                mCollider.enabled = true;
            });
        }