示例#1
0
    // Update is called once per frame
    void Update()
    {
        timeBeforeReturn -= Time.deltaTime;
        if (posInQueue > 0 && transform.position.z >= -19 - 4 * posInQueue)
        {
            transform.position = new Vector3(transform.position.x, transform.position.y, -19 - 4 * posInQueue);
            return;
        }

        if (posInQueue == 0 && queueManager.isSomoneInside && transform.position.z >= -19)
        {
            transform.position = new Vector3(transform.position.x, transform.position.y, -19);
            return;
        }

        //if (queueManager.isSomoneInside && posInQueue == 0 && transform.position.z >= -19 - 4 * posInQueue)
        //return;
        //if (queueManager.isSomoneInside && posInQueue >= 0 && transform.position.z >= -19)
        //return;

        //if (transform.position.z < -19 - 4 * posInQueue && posInQueue > 0)
        //{
        //return;
        //}



        if (transform.position.z > -19)
        {
            if (transform.position.z < -4) // Est en train de se déplacer à l'intérieur
            {
                queueManager.isSomoneInside = true;
            }
            if (posInQueue == 0) // Si position est de 0, enlève de la queue
            {
                queueManager.leaveQueue(this);
                posInQueue = -1;
            }
        }
        if (transform.position.z > -18) // Arrive devant les portes
        {
            doorLeftAnim.SetBool("opendoor", true);
            doorRightAnim.SetBool("opendoor", true);
        }
        if (transform.position.z > -12) // Fermeture des portes
        {
            doorLeftAnim.SetBool("opendoor", false);
            doorRightAnim.SetBool("opendoor", false);
        }
        if (transform.position.z > -4 && posInQueue <= -1) // Fini son truc..
        {
            queueManager.isSomoneInside = false;
            posInQueue = -2;
        }



        if (currentIdx < startPath.Count && !isMoveCouroutineRunning && startStartMove)
        {
            isMoveCouroutineRunning = true;
            if (hasStoreData)
            {
                animator._animRun = true;
            }
            else
            {
                animator._animRunHolding = true;
            }
            StartCoroutine(MoveNext(this.transform.position, startPath));
            currentIdx++;
        }
        else if (endStartMove)
        {
            animator._animRunHolding = false;
            currentIdx = 0;
            isMoveCouroutineRunning = false;


            if (!hasStoreData)
            {
                dataCube.GetComponent <Bloc>().ReleaseBloc();
                dataCube = null;
            }
            else
            {
                if (addressDisplay.address.TryGetValue(cubeIdx, out int idx))
                {
                    memoryManagement.FreeMemory(idx, cubeIdx, cubeSize);
                }
                else
                {
                    print("Key Error");
                }
            }


            startStartMove = false;
            startEndMove   = true;
            endStartMove   = false;
        }
        if (currentIdx < endPath.Count && !isMoveCouroutineRunning && startEndMove && !endEndingMove)
        {
            animator._animRun       = true;
            isMoveCouroutineRunning = true;
            StartCoroutine(MoveNext(transform.position, endPath));
            currentIdx++;
        }
        else if (endEndingMove && timeBeforeReturn < -10)
        {
            animator._animRun       = false;
            currentIdx              = 0;
            isMoveCouroutineRunning = false;
            startEndMove            = false;
            if (!hasStoreData)
            {
                hasStoreData     = true;
                timeBeforeReturn = Random.Range(5, 40);
            }
            else
            {
                posInQueue = -2;
                Destroy(this.gameObject);
            }
        }
        if (timeBeforeReturn <= 0 && timeBeforeReturn > -10)
        {
            timeBeforeReturn = -10.0f;
            queueManager.addCharacter(this);
            currentIdx = 0;
            isMoveCouroutineRunning = false;
            startStartMove          = true;
            endStartMove            = false;
            endEndingMove           = false;
            startEndMove            = false;
            currentIdx         = 0;
            posInQueue         = -1;
            transform.position = new Vector3(7.0f, 1.5f, -40.0f);
        }
    }