예제 #1
0
 //#TARGET
 public void SetTarget()
 {
     Debug.Log("^^^^^^^^ TARGET --- SetTarget UFO");//#TARGET
     if (_dataUfo != null)
     {
         //_dataUfo.SetTargetPosition(Storage.Person.PersonsTargetPosition);
         _dataUfo.SetTargetPosition(Storage.Person.PersonsTargetPosition);
     }
 }
예제 #2
0
    IEnumerator MoveObjectToPosition()
    {
        Vector3 lastPositionForLock      = transform.position;
        Vector3 lastPositionForMoveField = transform.position;

        int   stepTest      = 0;
        int   stepLimitTest = 10;
        float minDist       = 0.005f; //0.01f;

        int   speed = 5;
        float step  = speed * Time.deltaTime;


        if (!Helper.IsDataInit(this.gameObject))
        {
            //yield return null;
            yield break;
        }

        //@SAVE@  var dataUfo = FindObjectData() as SaveLoadData.GameDataUfo;
        _dataUfo = FindObjectData("MoveObjectToPosition Init") as ModelNPC.GameDataUfo;

        while (true)
        {
            if (Storage.Instance.IsLoadingWorld)
            {
                Debug.Log("_______________ LOADING WORLD ....._______________");
                yield return(null);
            }

            if (Storage.Instance.IsCorrectData)
            {
                Debug.Log("_______________ RETURN CorrectData ON CORRECT_______________");
                yield return(null);
            }

            if (_dataUfo == null)
            {
                Debug.Log("########################## UFO MoveObjectToPosition dataUfo is EMPTY");
                //Debug.Log("*** DESTROY : " + this.gameObject.name);
                //Storage.Instance.AddDestroyRealObject(this.gameObject);
                //@CD@
                Storage.Fix.CorrectData(null, this.gameObject, "MoveObjectToPosition");

                yield break;
            }

            stepTest++;
            if (stepTest > stepLimitTest)
            {
                float distLock = Vector3.Distance(lastPositionForLock, transform.position);
                if (distLock < minDist)
                {
                    //Debug.Log("MoveObjectToPosition ------ UFO LOCK !!!!  > " + distLock);
                    _dataUfo.SetTargetPosition();
                }
                lastPositionForLock = transform.position;
                stepTest            = 0;
            }

            Vector3 targetPosition = _dataUfo.TargetPosition;
            Vector3 pos            = Vector3.MoveTowards(transform.position, targetPosition, step);

            if (_rb2d != null)
            {
                _rb2d.MovePosition(pos);
            }
            else
            {
                //@[email protected]
                Debug.Log("UFO MoveObjectToPosition Set position 2 original........");
                transform.position = pos;
            }

            //+++++++++++ RESAVE Next Position ++++++++++++
            bool res = ResavePositionData();

            if (!res)
            {
                Debug.Log("########### STOP MOVE ON ERROR MOVE");
                if (this.gameObject != null)
                {
                    Debug.Log("%%%%%%%%%%%%%%%%%%%%%%%%%%%  MoveObjectToPosition " + this.gameObject.name);
                }
                Destroy(this.gameObject);
                yield break;
            }

            float dist = Vector3.Distance(targetPosition, transform.position);
            //Debug.Log("MoveObjectToPosition ------ UFO distance to point  > " + dist);
            if (dist < minDist)
            {
                _dataUfo.SetTargetPosition();
            }

            yield return(null);
        }
    }