Esempio n. 1
0
    void Update()
    {
        Debug.DrawLine(transform.position, target, Color.green);
        if (isFlyered && flyerTime < 2.0f)
        {
            velocity = Vector3.zero;
            transform.GetComponent <Renderer>().material = flyered;
            if (flyer != null)
            {
                velocity = Vector3.zero;
                flyers.Remove(flyer);
                Destroy(flyer);
            }
            //Flyered, Wait 2s;
            if (flyerTime < 2.0f)
            {
                flyerTime += Time.deltaTime;
            }
        }
        else if (flyerTime >= 2.0f)
        {
            flyerTime = 0;
            isFlyered = false;
            transform.GetComponent <Renderer>().material = notFlyered;
        }
        else
        {
            if (!isFlyered)
            {
                isFlyered = CollisionWithFlyer();
            }

            if (traversing)
            {
                Seek();
                if (chair != null)
                {
                    chair.transform.GetComponent <CapsuleCollider>().enabled = true;
                    CollisionAvoidance(chair.parent, -1);
                }
                else
                {
                    CollisionAvoidance(-1, -1);
                }
                Move();
            }

            if (shopping)
            {
                if (Vector3.Distance(target, transform.position) > obstacleDistance && chair == null)
                {
                    Seek();
                    CollisionAvoidance(-1, shopVisited);
                    Move();
                }
                else
                {
                    if (chair == null)
                    {
                        chair    = objectController.GetEmptyChair();
                        target   = chair.transform.position;
                        velocity = Vector3.zero;
                        forces.Clear();
                    }
                    //Inside Shop, Wait 1s;
                    if (shopTime <= 1.0f)
                    {
                        shopTime += Time.deltaTime;
                    }
                    else
                    {
                        if (Vector3.Distance(target, transform.position) > 4f)
                        {
                            Seek();
                            CollisionAvoidance(chair.parent, shopVisited);
                            Move();
                        }
                        else
                        {
                            transform.position = target;
                            chair.transform.GetComponent <CapsuleCollider>().enabled = false;
                            velocity = Vector3.zero;
                            forces.Clear();
                            if (sitTime < 3.0f)
                            {
                                sitTime += Time.deltaTime;
                            }
                            else
                            {
                                target     = new Vector3(99f, 0, Random.Range(-15f, 15f));
                                traversing = true;
                                shopping   = false;
                                Seek();
                                CollisionAvoidance(chair.parent, -1);
                                Move();
                                objectController.ChairReset(chair);
                            }
                        }
                    }
                }
            }
        }
    }